trivial: Add fu_firmware_parse_file() helper for future use

This commit is contained in:
Richard Hughes 2019-10-10 15:30:44 +01:00
parent 341ab10808
commit f591a3594b
2 changed files with 59 additions and 0 deletions

View File

@ -121,6 +121,31 @@ fu_firmware_parse (FuFirmware *self, GBytes *fw, FwupdInstallFlags flags, GError
return fu_firmware_parse_full (self, fw, 0x0, 0x0, flags, error);
}
/**
* fu_firmware_parse_file:
* @self: A #FuFirmware
* @file: A #GFile
* @flags: some #FwupdInstallFlags, e.g. %FWUPD_INSTALL_FLAG_FORCE
* @error: A #GError, or %NULL
*
* Parses a firmware file, typically breaking the firmware into images.
*
* Returns: %TRUE for success
*
* Since: 1.3.3
**/
gboolean
fu_firmware_parse_file (FuFirmware *self, GFile *file, FwupdInstallFlags flags, GError **error)
{
gchar *buf = NULL;
gsize bufsz = 0;
g_autoptr(GBytes) fw = NULL;
if (!g_file_load_contents (file, NULL, &buf, &bufsz, NULL, error))
return FALSE;
fw = g_bytes_new_take (buf, bufsz);
return fu_firmware_parse (self, fw, flags, error);
}
/**
* fu_firmware_write:
* @self: A #FuFirmware
@ -148,6 +173,33 @@ fu_firmware_write (FuFirmware *self, GError **error)
return fu_firmware_get_image_default_bytes (self, error);
}
/**
* fu_firmware_write_file:
* @self: A #FuFirmware
* @file: A #GFile
* @error: A #GError, or %NULL
*
* Writes a firmware, typically packing the images into a binary blob.
*
* Returns: %TRUE for success
*
* Since: 1.3.3
**/
gboolean
fu_firmware_write_file (FuFirmware *self, GFile *file, GError **error)
{
g_autoptr(GBytes) blob = NULL;
blob = fu_firmware_write (self, error);
if (blob == NULL)
return FALSE;
return g_file_replace_contents (file,
g_bytes_get_data (blob, NULL),
g_bytes_get_size (blob),
NULL, FALSE,
G_FILE_CREATE_NONE,
NULL, NULL, error);
}
/**
* fu_firmware_add_image:
* @self: a #FuPlugin

View File

@ -48,6 +48,10 @@ gboolean fu_firmware_parse (FuFirmware *self,
GBytes *fw,
FwupdInstallFlags flags,
GError **error);
gboolean fu_firmware_parse_file (FuFirmware *self,
GFile *file,
FwupdInstallFlags flags,
GError **error);
gboolean fu_firmware_parse_full (FuFirmware *self,
GBytes *fw,
guint64 addr_start,
@ -56,6 +60,9 @@ gboolean fu_firmware_parse_full (FuFirmware *self,
GError **error);
GBytes *fu_firmware_write (FuFirmware *self,
GError **error);
gboolean fu_firmware_write_file (FuFirmware *self,
GFile *file,
GError **error);
void fu_firmware_add_image (FuFirmware *self,
FuFirmwareImage *image);