JSPM

ip2buf

2.0.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 9981
  • Score
    100M100P100Q123774F
  • License MIT

Convert IPv4 or IPv6 address to the Buffer.

Package Exports

  • ip2buf

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (ip2buf) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

ip2buf

travis npm license downloads

Convert IPv4 or IPv6 address to the Buffer.

Usage

const { pton4, pton6 } = require('ip2buf')

pton4('8.8.8.8') // Buffer<0x8, 0x8, 0x8, 0x8>
pton6('2001::')  // Buffer<0x20, 0x01, 0, ...>

Perfomance

  • IPv4
library time (2e6 times)
native 296.627ms
ip2buf 283.710ms
ipaddr.js 1728.538ms
  • IPv6
library time (1e6 times)
native 333.071ms
ip2buf 767.788ms
ipaddr.js 1828.334ms

API

  • pton(af: number, addr: string, [[dest: Buffer], index: number]): Buffer

Convert IPv4 or IPv6 address to the Buffer.

const { pton, constants: { IPV4_OCTETS, IPV6_OCTETS } } = require('ip2buf')

pton(IPV4_OCTETS, '127.0.0.1')
pton(IPV6_OCTETS, '::1')
  • pton4(addr: string, [[dest: Buffer], index: number]): Buffer

Convert IPv4 address to the Buffer.

  • pton6(addr: string, [[dest: Buffer], index: number]): Buffer

Convert IPv6 address to the Buffer.

  • constants: Object

    • IPV4_OCTETS - size of IPv4 target buffer.
    • IPV6_OCTETS - size of IPv6 target buffer.

License

MIT, 2017 (c) Dmitry Tsvettsikh