isaacs / node-tar

tar for node
ISC License
837 stars 183 forks source link

[QUESTION] how to make .c a stream.Readble #322

Closed nunuqq1 closed 2 years ago

nunuqq1 commented 2 years ago

minio can upload a readable stream, using minioClient.putObject('xxx', 'yyy.tar', someReadableStream) so how to transform the return value of tar.c() to a readable stream?

wraithgar commented 2 years ago

It already does return a readable stream: https://github.com/npm/node-tar/blob/main/lib/create.js#L100-L104

Pack is a readable stream. https://github.com/npm/node-tar/blob/main/lib/pack.js#L3

nunuqq1 commented 2 years ago

const tarReadableStream = tar.c({ gzip: false, basename: true }, ['./']) const putRet = await minioClient.putObject('xxx', 'yyy.tar', someReadableStream)

error TypeError: third argument should be of type "stream.Readable" or "Buffer" or "string"

function isReadableStream(arg) { return isObject(arg) && isFunction(arg._read); } // check if arg is boolean

minio use the code above to check

wraithgar commented 2 years ago

It's not an internal node readable stream it's a minipass stream. Because of that you may have to pipe it to another internal node stream to get other software that is expecting specific data types to work.

wraithgar commented 2 years ago

Or you can open up an issue w/ minio to ask them to support minpass streams.

nunuqq1 commented 2 years ago

thanks for reply, i've fix the issue using stream.Transform