mirror of
https://github.com/varun-r-mallya/sysprof.git
synced 2026-02-12 16:10:54 +00:00
libsysprof-analyze: decompress if necessary in dup_bytes()
If we are trying to get the file bytes and they are compressed, we may need to transparently decompress those bytes. That way if the API requested "/proc/cpuinfo" but really got "/proc/cpuinfo.gz" it still gets the same bytes to consume.
This commit is contained in:
@ -157,6 +157,23 @@ sysprof_document_file_dup_bytes (SysprofDocumentFile *self)
|
|||||||
|
|
||||||
len = ar->len;
|
len = ar->len;
|
||||||
|
|
||||||
|
if (self->compressed)
|
||||||
|
{
|
||||||
|
guint8 *data = (guint8 *)g_array_free (ar, FALSE);
|
||||||
|
g_autoptr(GInputStream) input = g_memory_input_stream_new_from_data (data, len, g_free);
|
||||||
|
g_autoptr(GOutputStream) memory_output = g_memory_output_stream_new_resizable ();
|
||||||
|
g_autoptr(GZlibDecompressor) zlib = g_zlib_decompressor_new (G_ZLIB_COMPRESSOR_FORMAT_GZIP);
|
||||||
|
g_autoptr(GOutputStream) zlib_output = g_converter_output_stream_new (memory_output, G_CONVERTER (zlib));
|
||||||
|
|
||||||
|
g_output_stream_splice (zlib_output,
|
||||||
|
input,
|
||||||
|
(G_OUTPUT_STREAM_SPLICE_CLOSE_SOURCE |
|
||||||
|
G_OUTPUT_STREAM_SPLICE_CLOSE_TARGET),
|
||||||
|
NULL, NULL);
|
||||||
|
|
||||||
|
return g_memory_output_stream_steal_as_bytes (G_MEMORY_OUTPUT_STREAM (memory_output));
|
||||||
|
}
|
||||||
|
|
||||||
return g_bytes_new_take (g_array_free (ar, FALSE), len);
|
return g_bytes_new_take (g_array_free (ar, FALSE), len);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user