Both index.js and test.js have some ugliness because of the way the code was ported from Go.
Here is an example:
{
desc: 'WAV audio #1',
data: Buffer.concat([
Buffer.from('RIFFb'),
Buffer.from([0xb8, 0x00, 0x00]),
Buffer.from('WAVEfmt '),
Buffer.from([0x12, 0x00, 0x00, 0x00, 0x06])
]),
contentType: 'audio/wave'
},
The problem is that Go strings with \x?? in them get encoded to bytes differently from Javascript strings with \x?? in them. In Javascript, something like \xff uses 2 bytes in a Buffer, but \x00 takes one byte. As a result, we need to have code like above to make sure Go byte buffers translate to equivalent Javascript byte buffers.
As part of cleanup:
- try and find a better idiom for code written above
- Cleanup all
\x00 in Javascript code because it can get confusing. It is not obvious upfront how many bytes does a given hexademical escape sequence take up
Both
index.jsandtest.jshave some ugliness because of the way the code was ported from Go.Here is an example:
The problem is that Go strings with
\x??in them get encoded to bytes differently from Javascript strings with\x??in them. In Javascript, something like\xffuses 2 bytes in a Buffer, but\x00takes one byte. As a result, we need to have code like above to make sure Go byte buffers translate to equivalent Javascript byte buffers.As part of cleanup:
\x00in Javascript code because it can get confusing. It is not obvious upfront how many bytes does a given hexademical escape sequence take up