Giter Site home page Giter Site logo

Comments (16)

ctalkington avatar ctalkington commented on May 26, 2024

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.

ctalkington avatar ctalkington commented on May 26, 2024

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.

danmilon avatar danmilon commented on May 26, 2024

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.

ctalkington avatar ctalkington commented on May 26, 2024

@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.

ctalkington avatar ctalkington commented on May 26, 2024

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.

danmilon avatar danmilon commented on May 26, 2024

Definitely.

from node-archiver.

ctalkington avatar ctalkington commented on May 26, 2024

ok then. ill see about making the needed changes and releasing v0.3.0 in the next two weeks.

from node-archiver.

ctalkington avatar ctalkington commented on May 26, 2024

guys let me know what you think of the latest commits.

from node-archiver.

danmilon avatar danmilon commented on May 26, 2024

Will do during the weekend.

from node-archiver.

ctalkington avatar ctalkington commented on May 26, 2024

@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.

danmilon avatar danmilon commented on May 26, 2024

So, as of 51a7dbf, finalize and addFile push the error in the callback, instead of emitting it.

My suggested flow is:

  1. if callback present cb(err)
  2. 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.

ctalkington avatar ctalkington commented on May 26, 2024

hum I define a fallback callback that throws err so eitherway works. not sure my pref at this moment.

from node-archiver.

danmilon avatar danmilon commented on May 26, 2024

ah, indeed. Currently you cannot use the library without callbacks because of addFiles 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.

bf avatar bf commented on May 26, 2024

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.

bf avatar bf commented on May 26, 2024

Please see my Pull request #8 for further information. Thank you.

from node-archiver.

ctalkington avatar ctalkington commented on May 26, 2024

this callback style has been implemented in latest commits scheduled to be part of v0.3.0

from node-archiver.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.