Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
deehill opened this issue Oct 8, 2021 · 0 comments

Comments

@deehill
Copy link

deehill commented Oct 8, 2021

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?

<src="safe-buffer.js"> <<< 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant