Fail to uncompress zip file created by 7zip
brynne8 opened this issue · comments
Deno 1.15.0
exit using ctrl+d or close()
> import * as fflate from './fflate.js';
undefined
> const rawdata = await Deno.readFile('county_border.zip');
undefined
> fflate.decompressSync(rawdata)
Uncaught Error: invalid length/literal
at inflt (file:///D:/git_work/loc2district/fflate.js:259:9)
at inflateSync (file:///D:/git_work/loc2district/fflate.js:920:10)
at Module.decompressSync (file:///D:/git_work/loc2district/fflate.js:1201:159)
at <anonymous>:2:8
> rawdata
Uint8Array(31903372) [
80, 75, 3, 4, 20, 0, 0, 0, 8, 0, 101, 91, 35, 83, 175,
100, 188, 138, 226, 205, 230, 1, 52, 251, 18, 7, 18, 0, 0, 0,
99, 111, 117, 110, 116, 121, 95, 98, 111, 114, 100, 101, 114, 46, 106,
115, 111, 110, 180, 157, 187, 202, 104, 61, 17, 134, 123, 175, 66, 172,
69, 114, 78, 150, 173, 96, 41, 246, 34, 226, 25, 193, 19, 30, 10,
17, 11, 65, 176, 17, 177, 241, 22, 44, 5, 11, 27, 5, 189, 26,
5, 239, 194, 247, 205, 154, 201, 188, 203, 195,
... 31903272 more items
]
Please attach or send this file so I can investigate the issue - this output alone doesn't really provide enough information to fix the issue.
The original file is too large for upload. I uploaded a small file which also produces this issue.
Sorry I misread your initial post. You're doing decompressSync
instead of unzipSync
- decompress
is only for GZIP, Zlib, or DEFLATE files, while unzip
is for ZIP files. So you can do this:
const archive= fflate.unzipSync(rawdata);
// For the file you sent me
const airports = archive['airports.dat'];
Let me know if that works for you.
I found some of the docs confusing in this regard. It states in the readme
fflate
can autodetect a compressed file's format as well
const compressed = new Uint8Array(
await fetch('/GZIPorZLIBorDEFLATE').then(res => res.arrayBuffer())
);
// Above example with Node.js Buffers:
// Buffer.from('H4sIAAAAAAAAE8tIzcnJBwCGphA2BQAAAA==', 'base64');
const decompressed = fflate.decompressSync(compressed);
With this example being so early in the docs, I assumed it was the preferred way to use the library and it performed internal logic (magic) to determine which internal function to use for all types of ZIP, GZIP, Zlib & DEFLATE. Caused me a lot of confusion until I tried some of the other functions. I followed this issue assuming it was a bug given my understanding of the API.
It would help inexperienced users like myself if there was a table in the docs matching the types of files to the API/function used for those types.
It works! Thank you. I'm also confused by
fflate can autodetect a compressed file's format as well
It would help inexperienced users like myself if there was a table in the docs matching the types of files to the API/function used for those types.
Thanks for the feedback, I'll close this issue after clarifying in the docs.