Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/reklatsmasters/ip2buf
:fire: :zap: Convert IPv4 or IPv6 address to the Buffer.
https://github.com/reklatsmasters/ip2buf
buffer ip ipv4 ipv6 javascript js node nodejs pton pton4 pton6
Last synced: 24 days ago
JSON representation
:fire: :zap: Convert IPv4 or IPv6 address to the Buffer.
- Host: GitHub
- URL: https://github.com/reklatsmasters/ip2buf
- Owner: reklatsmasters
- License: mit
- Created: 2016-11-27T20:04:34.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2018-01-02T10:22:59.000Z (almost 7 years ago)
- Last Synced: 2024-09-18T14:51:18.533Z (about 2 months ago)
- Topics: buffer, ip, ipv4, ipv6, javascript, js, node, nodejs, pton, pton4, pton6
- Language: JavaScript
- Homepage:
- Size: 43 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
# ip2buf
[![travis](https://travis-ci.org/reklatsmasters/ip2buf.svg?branch=master)](https://travis-ci.org/reklatsmasters/ip2buf)
[![npm](https://img.shields.io/npm/v/ip2buf.svg)](https://npmjs.org/package/ip2buf)
[![license](https://img.shields.io/npm/l/ip2buf.svg)](https://npmjs.org/package/ip2buf)
[![downloads](https://img.shields.io/npm/dm/ip2buf.svg)](https://npmjs.org/package/ip2buf)Convert IPv4 or IPv6 address to the Buffer.
## Usage
```js
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.
```js
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.## Related
* [date2buffer](https://github.com/ReklatsMasters/date2buffer) - convert Date to the Buffer.
## License
MIT, 2017 (c) Dmitry Tsvettsikh