Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

list archive contents: lzop #230

Closed
wants to merge 9 commits into from
55 changes: 37 additions & 18 deletions src/fr-command-cfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,13 @@ get_uncompressed_name_from_archive (FrCommand *comm,
char buffer[10];

if (g_input_stream_read (stream, buffer, 10, NULL, NULL) >= 0) {
unsigned char flag = buffer[3];
stokito marked this conversation as resolved.
Show resolved Hide resolved
/* Check whether the FLG.FNAME is set */
if (((unsigned char)(buffer[3]) & 0x08) != 0x08)
if ((flag & 0x08) != 0x08)
filename_present = FALSE;

/* Check whether the FLG.FEXTRA is set */
if (((unsigned char)(buffer[3]) & 0x04) == 0x04)
if ((flag & 0x04) == 0x04)
filename_present = FALSE;
}

Expand Down Expand Up @@ -93,9 +94,14 @@ get_uncompressed_name_from_archive (FrCommand *comm,
}


/**
* Parse `gzip -lq archive.gz` output:
* @param line output line in format "compressed uncompressed ratio uncompressed_name" e.g. "758185 3454395 78.1% file.txt"
* @param data FrCommand*
*/
static void
list__process_line (char *line,
gpointer data)
list__process_line_gzip(char *line,
gpointer data)
stokito marked this conversation as resolved.
Show resolved Hide resolved
{
FrCommand *comm = FR_COMMAND (data);
FileData *fdata;
Expand All @@ -105,8 +111,9 @@ list__process_line (char *line,
fdata = file_data_new ();

fields = split_line (line, 2);
if (strcmp (fields[1], "-1") != 0)
fdata->size = g_ascii_strtoull (fields[1], NULL, 10);
const char *field_uncompressed = fields[1]; // e.g. "3454395"
if (strcmp (field_uncompressed, "-1") != 0)
fdata->size = g_ascii_strtoull (field_uncompressed, NULL, 10);
g_strfreev (fields);

if (fdata->size == 0)
Expand Down Expand Up @@ -134,25 +141,37 @@ list__process_line (char *line,
fr_command_add_file (comm, fdata);
}

/* gzip let us known the uncompressed size. To get it run:
* $ gzip -l file.txt.gz
* compressed uncompressed ratio uncompressed_name
* 758185 3454395 78.1% file.txt
* We can simplify output with --quiet (-q) option:
* $ gzip -lq file.txt.gz
* 758185 3454395 78.1% file.txt
*/
static void
fr_command_cfile_list__gzip(FrCommand *comm)
{
fr_process_set_out_line_func (FR_COMMAND (comm)->process,
list__process_line_gzip,
comm);

fr_process_begin_command (comm->process, "gzip");
fr_process_add_arg (comm->process, "-l");
fr_process_add_arg (comm->process, "-q");
fr_process_add_arg (comm->process, comm->filename);
fr_process_end_command (comm->process);
fr_process_start (comm->process);
}


static void
fr_command_cfile_list (FrCommand *comm)
{
FrCommandCFile *comm_cfile = FR_COMMAND_CFILE (comm);

if (is_mime_type (comm->mime_type, "application/x-gzip")) {
/* gzip let us known the uncompressed size */

fr_process_set_out_line_func (FR_COMMAND (comm)->process,
list__process_line,
comm);

fr_process_begin_command (comm->process, "gzip");
fr_process_add_arg (comm->process, "-l");
fr_process_add_arg (comm->process, "-q");
fr_process_add_arg (comm->process, comm->filename);
fr_process_end_command (comm->process);
fr_process_start (comm->process);
fr_command_cfile_list__gzip(comm);
}
else {
/* ... other compressors do not support this feature so
Expand Down
7 changes: 6 additions & 1 deletion src/glib-utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,12 @@ eat_void_chars (const char *line)
return line;
}


/**
* Parse the line and return array of columns separated by space symbol and size of n_fields
* @param line
* @param n_fields how many colums/fields to parse
* @return NULL terminated array of fields with size of n_fields
*/
char **
split_line (const char *line,
int n_fields)
Expand Down