Skip to content

Clean up code that is used to create buffers #7

@deepakjois

Description

@deepakjois

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions