TooTallNate / node-wav

`Reader` and `Writer` streams for Microsoft WAVE audio files
MIT License
181 stars 37 forks source link

Use from React #29

Closed josesuero closed 5 years ago

josesuero commented 5 years ago

I need to verify the specs of a wav file on my frond-end before uploading, I currently have a the base64 of the file which i'm converting to a readable stream using fetch:

const fileReader = new FileReader(); fileReader.onloadend = () => {

            fetch(fileReader.result)
              .then(res => {
                  const reader = res.body.getReader();
                  ///????????
              });
          };
          fileReader.readAsDataURL(file);

But browser stream does not have a pipe method, is there a way I can pass a stream (or a buffer) to a function on the reader in order to get the header?

thanks in advance

josesuero commented 5 years ago

I also tried creating a readable stream like:

            const buffer = new Buffer(fileReader.result, 'base64')
            const readable = new Readable()
            readable._read = () => { } // _read is required but you can noop it
            readable.push(buffer)
            readable.push(null)

            readable.pipe(reader) // consume the stream

but I got bad "chunk id": expected "RIFF" or "RIFX", got "u+Zj"

On NodeJS this files gets processed correctly

josesuero commented 5 years ago

Got it, it was a problem with Base64 string, thanks again for a great library