Open keyiis opened 7 years ago
It seems you edited the issue without changing the title (the issue doesn't have anything to do with "zip.generateAsync is not a function").
zip.gen.generateAsync
seems strange, there is no gen
attribute on JSZip instance. I'll assume this is just a typo.
Do you have a stacktrace for this error ?
@dduponchel sorry it's my mistake,i already modify title and code :)
@dduponchel the dbFilePath
is path of sqlite database file,eg d:\db\test.db
@dduponchel if i use zlib,i get same error
fs.createReadStream(dbFilePath).pipe(zlib.createGzip()).pipe(fs.createWriteStream(dbFilePath+'.gz'));
@dduponchel i changed to generateNodeStream
,but get same error
my code
let zip = new JSZip();
zip.file(dbFilePath);
zip.generateNodeStream({ type: 'nodebuffer', streamFiles: true })
.pipe(fs.createWriteStream('out.zip'))
.on('finish', function () {
// JSZip generates a readable stream with a "end" event,
// but is piped here in a writable stream which emits a "finish" event.
console.log("out.zip written.");
});
error info
core.es5.js:1020 ERROR TypeError: Invalid non-string/buffer chunk
at validChunk (_stream_writable.js:209)
at WriteStream.Writable.write (_stream_writable.js:239)
at NodejsStreamOutputAdapter.ondata (_stream_readable.js:612)
at NodejsStreamOutputAdapter.EventEmitter.emit (events.js:81)
at addChunk (_stream_readable.js:284)
at readableAddChunk (_stream_readable.js:271)
at NodejsStreamOutputAdapter.Readable.push (_stream_readable.js:238)
at StreamHelper.<anonymous> (NodejsStreamOutputAdapter.js:22)
at ConvertWorker.<anonymous> (StreamHelper.js:172)
at ConvertWorker.emit (GenericWorker.js:122)
at ConvertWorker.push (GenericWorker.js:48)
at ConvertWorker.processChunk (ConvertWorker.js:21)
at ZipFileWorker.<anonymous> (GenericWorker.js:154)
at ZipFileWorker.emit (GenericWorker.js:122)
at ZipFileWorker.push (GenericWorker.js:48)
at ZipFileWorker.push (ZipFileWorker.js:371)
at ZipFileWorker.flush (ZipFileWorker.js:450)
at ZipFileWorker.end (GenericWorker.js:59)
at ZipFileWorker.resume (ZipFileWorker.js:506)
at ConvertWorker.resume (GenericWorker.js:196)
at Immediate.<anonymous> (utils.js:384)
at ZoneDelegate.1804.ZoneDelegate.invokeTask (zone.js:424)
@dduponchel i can get source file data
var rs = fs.createReadStream(dbFilePath);
rs.on('data', (data:any)=>{
console.log(data);
}).on('close', function() {
console.log('close');
});
That looks like an issue with the type of an object, not the content of the input file. I think you could use any content to trigger the issue.
zip.file(dbFilePath)
looks strange: with only a path, you are using file(name), not file(name, data [,options]), meaning you don't add any content.
I suspect JSZip to interact badly with either angular's zones or different electron contexts. I tested your code inside the electron-quick-start
project and with a freshly bootstrapped angular 4 project but I can't reproduce the issue.
Would you be able to create a minimal project to reproduce the issue ?
@dduponchel thanks reply! i'm a little confused,i already give file path to jszip,it should read file through the path automatically?
Your code, on its own, works. I think the issue appears in some use cases with angular4/electron. To understand what's going on, I need to reproduce the error on my side. Just adding angular4 or electron in my tests couldn't reproduce it (the code still works). That's why I need a complete project, if possible a minimal one (like stackoverflow minimal example for example) which triggers the error.
@keyiis Was your issue fixed?
@haydonduan @keyiis @dduponchel I recently moved the config to webpack and jszip started throwing errors like:
TypeError: Invalid non-string/buffer chunk
at validChunk (_stream_writable.js:209:10)
at WriteStream.Writable.write (_stream_writable.js:239:21)
at NodejsStreamOutputAdapter.ondata (webpack-internal:///240:531:20)
at NodejsStreamOutputAdapter.EventEmitter.emit (webpack-internal:///46:81:17)
at readableAddChunk (webpack-internal:///240:198:18)
at NodejsStreamOutputAdapter.Readable.push (webpack-internal:///240:157:10)
at StreamHelper.eval (webpack-internal:///868:22:19)
at ConvertWorker.eval (webpack-internal:///340:172:20)
at ConvertWorker.emit (webpack-internal:///21:122:42)
at ConvertWorker.push (webpack-internal:///21:48:14)
Uncaught Error: The data of 'testFolder/c4e5ef9e-5edd-4ecc-8a17-f5e803a3d079.png' is in an unsupported format
Any thoughts?
@haydonduan i give up jszip
@haydonduan我放弃 jszip Can you recommend any other ZIP plug-ins you are using now?
I used jszip(3.1.4) with electron/angular4/typescript,but not work. my code
error info