buffer-factory
    TypeScript icon, indicating that this package has built-in type declarations

    1.0.9 • Public • Published

    Build Status Coverage Status Try buffer-factory on RunKit DeepScan grade

    Buffer Factory - (中文版README)

    buffer-factory makes it no pain to create a Buffer object by encapsulate Buffer.from an new Buffer().

    This module has been well unit tested and documented.

    Usage

    install

    npm i buffer-factory

    use

    const bufferFactory = require('buffer-factory')
    bufferFactory.create('2b', 'hex');
     
    // deprecated
    bufferFactory('2b', 'hex');

    Implementation

    Buffer.from is preffered to be used when it's accessible.

    Buffer.from is added from v5.10.0, as the api document shows. But some node version, v4.2.6 for example, Buffer.from is a function, however, there is an error when you call Buffer.from(string, encoding)(error like hex is not function). So I also take the node version into account.

    For low versions of Node.js, this module use new Buffer(...).

    You're free to pass in the same params as Buffer.from(...) and new Buffer(...), I will handle the rest for you.

    You're also free to check index.js for the implementation code :).

    Install

    npm i buffer-factory

    DownloadsWeekly Downloads

    336

    Version

    1.0.9

    License

    MIT

    Unpacked Size

    78.8 kB

    Total Files

    9

    Last publish

    Collaborators

    • sunshine1988