feross / feross/buffer

NodeJS Buffer returns different result for same operation

Open
#307 1 comment 3 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
1.9k
Forks
260
PR merge metrics
No merged PRs in 30d

Description

I've recently switched to this library on a @ionic/vue app and since then some of my unit tests fail since they run under node environment. The following is an example that returns a different value depending on where it runs on.

```html





Buffer




const { Buffer } = window.buffer;
const intInBase64 = "/w==";

function decodeBase64ToInt(value) {
const buf = Buffer.from(value, 'base64');
const bytes = new Int8Array(buf.buffer);

return bytes[0];
}

console.log(decodeBase64ToInt(intInBase64))

```

```js
const intInBase64 = "/w==";

function decodeBase64ToInt(value) {
const buf = Buffer.from(value, 'base64');
const bytes = new Int8Array(buf.buffer);

return bytes[0];
}

console.log(decodeBase64ToInt(intInBase64))
```

Running the HTML snippet on the browser will return `-1` and running the second snippet with `node` will return `47`.
How come?

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.