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?

You can also use TypeArray.from() method on all Typed Arrays to convert between normal arrays:

<!-- begin snippet: js hide: false console: true babel: false --> <!-- language: lang-js -->
const values = [-1, 94, 43, 34]

const byteArr = Int8Array.from(values)
const original = Array.from(byteArr)

console.log({ byteArr, original })
<!-- end snippet -->

Bonus: This works in node and also the browser