feross / feross/safe-buffer

"safe-buffer" -- Can this be used/dropped into a Javascript app for a Browser/Extension (Chrome)

Open
#34 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
345
Forks
47
PR merge metrics
No merged PRs in 30d

Description

Update::

In my testing, I've managed to use nodejs/npm/bowserify to create a "safe-buffer.js" that might work in the browser.

However, I don't have a clue (yet) as to how to invoke the "Browser" for my test.

In a normal nodejs kind of script, the following line would be used:
var Buffer = require('safe-buffer').Buffer

I'm not quite sure what my test should have to init a Buffer in my script.

The sample code I'm trying to test is:
As a test, the lines of code I'm trying to test are: (within the request_test3.js
.
const compress = str => Buffer.from(pako.deflateRaw(str)).toString('base64');
console.log(compress('asdfasdfasdfasdf')); //SyxOSUtEwgA=
.
.

Any thoughts??

thanks

Hi.

I'm doing a test app in Chrome/Extension. Dealing with the pako.gzip compression in the Extension, and decompressing on the Server/Php side.

The issues I seem to be running into imply that possible solutions use code which need to have a "polyfil" for the "Buffer".

Given that my skillset with Javascript, is limited, I was wondering if this might work so I can test it out?

<<< this kind of thing?

thanks

ps.
The test "code" from stackoverflow that I'm referring to is :

//JS
const pako = require('pako');
const compress = str => Buffer.from(pako.deflateRaw(str)).toString('base64');
console.log(compress('asdfasdfasdfasdf')); //SyxOSUtEwgA=
//PHP
function decompress($str) { return gzinflate(base64_decode($str)); }
echo decompress('SyxOSUtEwgA='); //asdfasdfasdfasdf

(the author states)
Note: Buffer instances are also Uint8Array instances, hence we don't need to convert the Buffer to a Uint8Array before giving it to pako.

For JS, this works out of the box in NodeJs. In a browser environment, you will need a polyfil for Buffer.

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.