What file extension to use with new CompressionStream('gzip')?

150 views
Skip to first unread message

guest271314

unread,
Jul 10, 2022, 1:25:12 PM7/10/22
to blink-network-dev
When writing a file piped through new CompressionStream('gzip') what file extension should the file be set to?

When the extension is set to .zip or .gz https://googlechromelabs-unarchiver.glitch.me/ fails to decompress or read the archive.

PhistucK

unread,
Jul 10, 2022, 2:05:49 PM7/10/22
to guest271314, blink-network-dev
I believe it is .gz, however, the unarchiver you linked to only seems to support .zip and .tar. It uses jszip behind the scenes and tar-stream.
.gz has a different magic number than .zip, so it is possible that jszip is a bit strict (and/or that .gz and .zip differ in their structure), despite the fact that both of the formats support the DEFLATE compression.
If you find that jszip is able to handle the file, it might be an issue with the unarchiver itself.

Also, since .gz has a magic number, it is possible that the compression stream generates a content that is "too raw" (only the compressed data and no other structure) to be considered .gz or .zip.
(I realise that .zip can also have no magic number - but my knowledge of the required structure is limited)

PhistucK


On Sun, Jul 10, 2022 at 6:25 PM guest271314 <guest...@gmail.com> wrote:
When writing a file piped through new CompressionStream('gzip') what file extension should the file be set to?

When the extension is set to .zip or .gz https://googlechromelabs-unarchiver.glitch.me/ fails to decompress or read the archive.

--
You received this message because you are subscribed to the Google Groups "blink-network-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to blink-network-...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/blink-network-dev/44ba4dd9-e239-4e3c-b6a0-04e547e94348n%40chromium.org.

guest271314

unread,
Jul 10, 2022, 2:24:06 PM7/10/22
to blink-network-dev, PhistucK, blink-network-dev, guest271314
I tried .gz, .zip and .tar.gz. The GoogleChromeLabs demo fails to decompress any of the archives.

Test

(async()=>{
  readable = new ReadableStream({
    start(c) {
      c.enqueue(new TextEncoder().encode('a'.repeat(1000)));
      c.close();
    }
  }).pipeThrough(new CompressionStream('gzip'));
  handle = await showSaveFilePicker({
    startIn: 'downloads',
    suggestedName: 'test.gz'
  });
  console.log(handle);
  writable = await handle.createWritable();
  await readable.pipeTo(writable);
}
)();

I can read the archive with 

  request = (await fetch('chrome-extension://xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/test.gz')).body.pipeThrough(new DecompressionStream('gzip'))
  text = await new Response(request).text();
  console.log(text);

Thus the question: What file extension to set for archives created by new CompressionStream('gzip')?

PhistucK

unread,
Jul 10, 2022, 2:28:40 PM7/10/22
to guest271314, blink-network-dev
I now realise that my answer was a bit contradictory because .gz has a magic number, so it probably cannot be it.
I believe it has no actual extension, because it seems like its purpose is for transferring content between browser/server, not for archiving content for storage. Making another piece of the magic available to authors.

PhistucK

guest271314

unread,
Jul 10, 2022, 2:44:25 PM7/10/22
to blink-network-dev, PhistucK, blink-network-dev, guest271314
> not for archiving content for storage. 


Use cases
  • Compressing data for upload.
  • Compression and decompression for
    • Native files
    • Network protocols
    • In-memory databases
  • Lazy decompression for downloads.

See the list item and the first sub-list item "Compression and decompression for -> Native files".

I asked here to see if file naming was considered during development of the specification and implementation. If not then it should be. 

Either way the GoogleChromeLabs example does not work with any of the listed file extensions nor with no file extension. That code is broken; should support reading what it writes. Perhaps overreliant on external code for a demo when the purpose of the Compression Streams is to not rely on external code. I filed this https://github.com/GoogleChromeLabs/unarchiver/issues/22

Adam Rice

unread,
Jul 10, 2022, 10:34:38 PM7/10/22
to guest271314, blink-network-dev, PhistucK
The file extension should be ".gz".

PhistucK

unread,
Jul 11, 2022, 4:11:21 AM7/11/22
to guest271314, blink-network-dev
> That code is broken; should support reading what it writes.

Except... It does not write, it is an unarchiver, not an archiver.

PhistucK

Reply all
Reply to author
Forward
0 new messages