Giter Club home page Giter Club logo

base64-arraybuffer's Introduction

base64-arraybuffer

CI NPM Downloads NPM Version

Encode/decode base64 data into ArrayBuffers

Installing

You can install the module via npm:

npm install base64-arraybuffer

API

The library encodes and decodes base64 to and from ArrayBuffers

  • encode(buffer) - Encodes ArrayBuffer into base64 string
  • decode(str) - Decodes base64 string to ArrayBuffer

Testing

You can run the test suite with:

npm test

License

Copyright (c) 2012 Niklas von Hertzen Licensed under the MIT license.

base64-arraybuffer's People

Contributors

arv avatar niklasvh avatar sanemat avatar skrat avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

base64-arraybuffer's Issues

Accept a Uint8Array so as not to waste memory and time?

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),


Special characters get lost?

console.log(encode(decode('P-vo4HxWwOyJEZsd-7dYER4L7VLMZzDD0Hs6IdiMT_k')))
// Output: PAvo4HxWwOyJEZsdA7dYER4L7VLMZzDD0Hs6IdiMTAk=

Am I doing something wrong?

The `sources` field in the sourcemap seems invalid

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

Decode allow re-using a pre-allocated buffer?

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?

Decode giving empty array buffer

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{}

Benchmark against `btoa` and `atob`?

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?

Memory leak in encode

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

It seems not support Unicode

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=

Version 1.1 publication

Is it possible to publish version 1.1 on npm? The currently available one no longer works with current ArrayBuffer API.

Encode in C# and decode with javascript

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);

Temporary backup files in npm package

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.