mafintosh / tar-stream

tar-stream is a streaming tar parser and generator.
MIT License
408 stars 92 forks source link

Writing object as entry #46

Closed gillesdemey closed 1 year ago

gillesdemey commented 8 years ago

Bumped my head against the wall for a while until I figured out that object serialization doesn't happen automatically when writing objects to an entry.

We could do something similar to https://github.com/mafintosh/tar-stream/blob/8e3b1749a322937238236ad05a3ec1122f32ed22/pack.js#L127 and call JSON.stringify on the object to prevent the user from committing an empty buffer to the file?

mafintosh commented 8 years ago

hmm i'm not sure what you are asking for? why don't you just stringify your object before passing it to .entry?

gillesdemey commented 8 years ago

That's what I did, my initial suggestion was to stringify the payload for them automatically if we detect that they're trying to write an object to the entry (most likely a JSON object)?

mafintosh commented 8 years ago

hmm i think that should be up the user of the module to do. we could throw if it's not a string or a buffer though to help the user though.

gillesdemey commented 8 years ago

I think it makes sense to inform the user, but I'm wondering if it would break existing usage of the library where someone would do something like tar.entry('foo.json', {}) to write an empty buffer to the file.