Comments (16)
finalize
adds the extra closing bits to the file via the stream so it has to be async as it has to wait on the stream to close before it can give anything back.
errors are emitted as events so you can catch them with archive.on('error', function (err) { .. })
.
from node-archiver.
also, i do plan to make these error
events provide an object vs a simple string in the near future so that more detailed info can be provided.
from node-archiver.
It's not about not being able to catch errors.
The problem with breaking the cb(err, res)
convention is that finalize
can't be used with control flow libraries / other code that expects the first argument to be the error.
from node-archiver.
@danmilon fair point. i think i can make this happen as the next major release since it has breaking changes. would really love to have a few testers for this project to help make it more robust in the long term.
from node-archiver.
you guys mention finalize
but when I do it, id prob also do it for addFile
as when i do the change i want it to be consistent.
from node-archiver.
Definitely.
from node-archiver.
ok then. ill see about making the needed changes and releasing v0.3.0 in the next two weeks.
from node-archiver.
guys let me know what you think of the latest commits.
from node-archiver.
Will do during the weekend.
from node-archiver.
@danmilon thanks. i've overhauled the docs and examples too so let me know what you think and thanks for your feedback thus far.
from node-archiver.
So, as of 51a7dbf, finalize
and addFile
push the error in the callback, instead of emitting it.
My suggested flow is:
- if callback present
cb(err)
- else
.emit('error', err)
This way errors will never pass silently. If there is no error event listener, the node core will throw it, by design.
@ctalkington, what do you think?
from node-archiver.
hum I define a fallback callback that throws err so eitherway works. not sure my pref at this moment.
from node-archiver.
ah, indeed. Currently you cannot use the library without callbacks because of addFile
s having to be serialized. I plan to write a PR to fix this, in which case it does make sense to not provide a callback and centrally manage errors in the error listener.
If I send a PR with the changes I proposed earlier will it be accepted?
from node-archiver.
Dan, I have already implemented a true asynchronous way to use addFile
with zip archives. Please check out my fork https://github.com/bf/node-archiver where this is implemented. I havent sent a PR yet because I wanted to implement the same for creating .tar files.
The basic approach is to keep an internal queue which adds each file after the last one is finished. Because of this, I can use addFile
with Step.js in a loop:
Step (
function () {
var group_callback = this.group();
_.each(arr, function (val, key) {
archive.addFile(source, {
name: 'test'
}, group_callback());
});
}
);
from node-archiver.
Please see my Pull request #8 for further information. Thank you.
from node-archiver.
this callback style has been implemented in latest commits scheduled to be part of v0.3.0
from node-archiver.
Related Issues (20)
- ESM HOT 1
- .directory() generate a empty folder, compress completed will remove the empty folder,could I retain the empty folder?
- Class extends value undefined is not a constructor or null HOT 1
- Is there a way to know how many files were ultimately compressed? HOT 2
- Question: Were there any API changes from 5.3 to 6.x? HOT 1
- Recommendation for an unzip library? HOT 1
- Overwrite existing files
- Missing Release of Resource after Effective Lifetime [High Severity] HOT 1
- zlib level 0 stops the progress of ongoing read streams
- Improve docs around append callback? HOT 1
- How to convert csv to 7z HOT 1
- Heap out of memory with archiver.append() HOT 1
- Append CSV file line by line
- `append()` fails after upgrading from v6 to v7 HOT 4
- Cannot add file named `\` HOT 2
- Archiver Version 7.0 might be breaking due to ESM HOT 1
- [Question] Can this library work with Web Streams ?
- Create a single zip file incrementally? HOT 1
- Produce the same zip file all time HOT 1
- Zip file produced has 0 bytes HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from node-archiver.