-
-
Notifications
You must be signed in to change notification settings - Fork 63
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
[FeatureRequest] Buffer or UInt8Array for input #99
Comments
There is a way to work around. The idea is quite simple:
Here's the sample code: import StreamZip from 'node-stream-zip';
import { createFsFromVolume, Volume } from 'memfs';
import { Union } from 'unionfs';
// setup
const volume = new Volume();
const memFs = createFsFromVolume(volume).promises;
const ufs = new Union();
ufs.use(fs).use(volume);
let memFileIndex = 0;
StreamZip.setFs(ufs);
async function readZipFromBuffer(buffer, callback) {
const file = `/file_${memFileIndex++}.zip`;
let zip;
try {
await memFs.writeFile(file, buffer);
zip = new StreamZip.async({ file });
return await callback(zip);
} finally {
if (zip) {
await zip.close();
}
await memFs.unlink(file);
}
}
// usage
const data = await readZipFromBuffer(buffer, async (zip) => {
// ... do whatever with zip
// return ...
}); Some references: |
That's a pretty drastic workaround...I'd prefer to be able to pass a buffer directly to |
Yeah, I hope for the same thing but this project seems to be inactive for a few years now. Alternatively we could've forked the project and make it accept a Buffer, yet I believe an implementation with the same |
Someone was saying in #97 that consuming a stream isn't really feasible because metadata is at the end of the file. But it would be nice to be able to at least read a
Buffer
, because I'd like to use this to read small zip files sent via HTTP form upload without having to save them to disk.The text was updated successfully, but these errors were encountered: