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

    2.4.0 • Public • Published

    NPM

    ci Coverage Status NPM Downloads NPM License

    Bencodec

    Library for decoding and encoding bencoded data.
    Compliant with the BitTorrent bencoding specification.

    Fast and easy to use.
    Written in TypeScript.
    Fully tested with 100% code coverage.
    Without dependencies.

    Installation

    npm yarn
    npm install --save bencodec yarn add bencodec

    Getting Started

    Import library

    typescript javascript
    import bencodec from 'bencodec' const bencodec = require('bencodec')

    Decode data

    By default, all strings will be parsed as buffers.

      const data = bencodec.decode( 'd3:bar4:spam3:fooi42ee' );
      // or
      const data = bencodec.decode( Buffer.from('d3:bar4:spam3:fooi42ee') );
      
      // data
      { bar: <Buffer 73 70 61 6d>, foo42 }

    To convert buffers to strings add stringify option.

    const data = bencodec.decode( 'd3:bar4:spam3:fooi42ee', { stringify: true } );
     
    // data
    { bar'spam', foo42 }
     

    Encode data

    By default method encode will return buffer.

      const data = bencodec.encode({ bar: 'spam', foo: 42 });  
      // <Buffer 64 33 ... 65 65>
      
      const data = bencodec.encode({ bar: 'spam', foo: 42 }, { stringify: true });
      // 'd3:bar4:spam3:fooi42ee'

    Tests

      npm test

    License

    This project is licensed under the MIT License - see the LICENSE file for details.

    Install

    npm i bencodec

    DownloadsWeekly Downloads

    18

    Version

    2.4.0

    License

    MIT

    Unpacked Size

    15 kB

    Total Files

    11

    Last publish

    Collaborators

    • isolomak