Open piranna opened 2 years ago
If I understand this correctly, you are requesting a new feature and not reporting a bug. Nowhere to my knowledge, we are advertising that you can pass strings to the Upload constructor. Or am I missing something?
To be honest, I also do not think we need to add this to tus-js-client and let users call Buffer.from
on their own to convert the string into a buffer. This way they also have full control over the encoding and it does not require a lot of work from the users.
Yes, It can be seen as an improvements, and although it's true users can call Buffer.from() on their own, it's so much common to be able to use both Buffers and strings for binary data or text, that's a bit annoying to need to do It yourself, that's why I ask to add it.
I have never seen binary data being handled in strings, especially not inside Node.js where you have the Buffer class. But let's not discuss this here.
After thinking a bit more about this, it might also be handy for our internals. We currently have an internal test helper which constructs buffers or blob out of strings: https://github.com/tus/tus-js-client/blob/b031f98d9fe71dc28d3b162ec47a22163db8b8d0/test/spec/helpers/utils.js#L8-L17
If we pull this functionality internally into tus-js-client we could also get rid of this function. Would you be interested in working on this?
We currently have an internal test helper which constructs buffers or blob out of strings:
Yes, my propose is to don't lead users to have to deal with this kind of hacks themselves.
If we pull this functionality internally into tus-js-client we could also get rid of this function. Would you be interested in working on this?
Sure, where can I start? Add the strings support and remove the internal getBlob()
function?
PR available at https://github.com/tus/tus-js-client/pull/493.
Describe the bug
At https://github.com/tus/tus-js-client/blob/master/lib/node/fileReader.js, it's being checked that the provided data is a Buffer instance or a Readable stream, but it's not possible to use a string, you need to convert it first to a Buffer yourself.
To Reproduce Steps to reproduce the behavior:
Upload()
class constructorExpected behavior
Allow to use strings as data input, maybe converting it internally to a Buffer if needed, but I think it can be provided directly.
Setup details Please provide following details, if applicable to your situation: