I am trying to determine what encoding scheme will give me the numbers -1 or -40 (the starting numbers for the file) for a jpeg file type.
A rest api I'm working on is expecting a byte array that looks like [-1, 94, 43, 34, etc]. In node.js I can have the byte array as hex, or any other encoding type, but I seem not able to get -1 or -40 for the starting value whichever encoding scheme I try.
In the documentation I saw an example in Java which uses the "toByteArray()" function, which seems to get the starting values (-1 or -40). Can anyone help me?
If I correctly understand your question, you can use
Buffer
to get file contents, then read the bytes from it into your array.Java
byte
type is a signed 8-bit integer, the equivalent in Node.js Buffer isbuf.readInt8()
.So you can read the required amount of
byte
s fromBuffer
into your array usingbuf.readInt8()
Or just convert it into
Int8Array
: