niklasvh / base64-arraybuffer Goto Github PK
View Code? Open in Web Editor NEWEncode/decode base64 data into ArrayBuffers
License: MIT License
Encode/decode base64 data into ArrayBuffers
License: MIT License
We internally used this package for encoding/decoding large pdf files and noticed our instance crashing on around 2gb of files. The instance had free memory of 12gb! After hours of debugging we narrowed it down to the encode function of this library. I read the encode function code and tried to figure out why? But couldn't find a leak. But from our testing and debugging, I am sure there's a memory leak in encode function (in nodejs v8) @niklasvh
decode(encode('im looking for a solution. do you have one?'))
"iv/lookinv/fov/a/solutio///d//yo//havf/onf8="
For example:
Use this words as an input:
Base 64 \u2014 Mozilla Developer Network
Add a test case such as:
it('encode "Base 64 \u2014 Mozilla Developer Network"', () => equal(encode(stringArrayBuffer("Base 64 \u2014 Mozilla Developer Network")), "QmFzZSA2NCDigJQgTW96aWxsYSBEZXZlbG9wZXIgTmV0d29yaw=="))
The result is
+ expected - actual
+QmFzZSA2NCDigJQgTW96aWxsYSBEZXZlbG9wZXIgTmV0d29yaw==
-QmFzZSA2NCAUIE1vemlsbGEgRGV2ZWxvcGVyIE5ldHdvcms=
Hi,
encode method for buffer is giving me base64 strng.. But reverse is not happening.
Its giving me empty ArrayBuffer.
Am I doing anything wrong?
Here is my code
var b64toBuff = require('base64-arraybuffer');
let data = fs.readFileSync(imagePath);
let c = b64toBuff.encode(data);
let d = b64toBuff.decode(c)
c gives me a base64 string.
But d gives me empty ArrayBuffer{}
I want to Encode my file in C# to base64 and decode it with this module in my Ionic App
I use this code to Encode in C# but it seems not get the true file in my Client when I decode it:
Byte[] bytes = File.ReadAllBytes(localFilePath); String file = Convert.ToBase64String(bytes);
Hi,
Thanks a lot for your work on this library! I'm curious if you perhaps benchmarked your solution against browser built-in functions btoa
and atob
?
If not, I could volunteer to set up a benchmark and create a PR to include the results in the readme if that's desirable? Do you have any preferance on how to benchmark?
Hi! It seems the sources
field in the sourcemap base64-arraybuffer.es5.js.map
is invalid:
{"version":3,"file":"base64-arraybuffer.es5.js","sources":["../../src/index.ts"],"sourcesContent":[null],"names":[], ...
It should be ../src/index.ts
I think.
node_modules/
└── base64-arraybuffer
├── dist
│ ├── base64-arraybuffer.es5.js
│ ├── base64-arraybuffer.es5.js.map
│ ...
├── package.json
├── README.md
└── rollup.config.ts
Not sure why though.
Related: socketio/socket.io-client#1520
Is it possible to publish version 1.1 on npm? The currently available one no longer works with current ArrayBuffer
API.
As it is, if you have some Uint8Array that is a view into a larger ArrayBuffer then a copy of the data is made in encode because new Uint8Array(someOtherUint8Array)
makes new ArrayBuffer with a copy of the data. Where as you could just use the Uint8Array passed in?
Basically this would change
exports.encode = function(arraybuffer) {
var bytes = new Uint8Array(arraybuffer),
To something like
exports.encode = function(arraybuffer) {
var bytes = (arrayBuffer instanceof Uint8Array || arrayBuffer instanceof Uint8ClampArray)
? arrayBuffer
: new Uint8Array(arraybuffer),
An install of version 0.1.2 from npm adds two temporary backup files to system. These files are README.md~
and package.json~
.
These seem to be deleted from git and hence similar update should be pushed to npm.
For repeated invocations with temporary data, there's an opportunity (not sure how great) for memory allocation savings if instead of always creating a new ArrayBuffer
, the decode
function allows an optional 2nd parameter for a reusable ArrayBuffer
that is console.assert()
'ed to be at least the length needed for decoding the base64 string.
Perhaps the decode
function could return the number of bytes written instead of an ArrayBuffer
if a buffer is provided - speculating usefulness for handling variable-byte input strings.
Would you be open to a PR for this?
console.log(encode(decode('P-vo4HxWwOyJEZsd-7dYER4L7VLMZzDD0Hs6IdiMT_k')))
// Output: PAvo4HxWwOyJEZsdA7dYER4L7VLMZzDD0Hs6IdiMTAk=
Am I doing something wrong?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.