Skip to content

An emulation of NodeJS's Buffer module. Used in BrowserFS.

License

Notifications You must be signed in to change notification settings

jvilk/bfs-buffer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

BrowserFS Buffer v0.1.7

An emulation of NodeJS's Buffer module. Used in BrowserFS.

Features

  • Space-efficient binary representation across browsers.
    • ArrayBuffer in modern browsers
    • CanvasPixelArray in older browsers that do not support typed arrays, but support the canvas.
    • Array of 32-bit ints in older browsers without the above.
  • Supports the entirety of the NodeJS Buffer API! (including string encoding)
    • ...with a few exceptions, due to browser limitations (see below).
  • Well-tested! Passes all of Node's Buffer tests.
    • The unit tests are located in the BrowserFS repository.

Use with Browserify

This module can be used with Browserify in place of its default Buffer module!

Here's the relevant configuration:

{
    builtins:
    {
        "buffer": require.resolve('bfs-buffer')
    },
    insertGlobalVars: {
        "Buffer": function() { return "require('bfs-buffer').Buffer" }
    }
}

Limitations

  • Does not support array indexing. e.g. you cannot do buff[0] = 3.
    • Browsers do not let you implement custom arrays, and merely setting the prototype of Buffer to Uint8Array, as in the official Node implementation of Buffer, is not portable across browsers.

About

An emulation of NodeJS's Buffer module. Used in BrowserFS.

Resources

License

Stars

Watchers

Forks

Packages

No packages published