Socket
Book a DemoInstallSign in
Socket

generic-hex-dump

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

generic-hex-dump

Get individual lines of a typical hex dump

latest
Source
npmnpm
Version
1.2.0
Version published
Maintainers
1
Created
Source

generic-hex-dump

Get individual lines of a typical hex dump. Use this to implement your own interface or whatever else you want.

Example

var Dump = require('generic-hex-dump');

var buf = Buffer('abcdefghijklmnopqrstuvwxyz0123456789><\x00\x00');
var dump = new Dump(buf.length);

var lines = dump.lines();
for (var i = 0; i < lines; i++) {
  var slice = dump.slice(buf, i);
  console.log(
    dump.offset(i),
    dump.hex(slice).join(' '),
    dump.strings(slice).join('')
  );
}

Output:

$ node example.js
000000 61 62 63 64 65 66 67 68 69 6a 6b 6c 6d 6e 6f 70 abcdefghijklmnop
000010 71 72 73 74 75 76 77 78 79 7a 30 31 32 33 34 35 qrstuvwxyz012345
000020 36 37 38 39 3e 3c 00 00 6789><..

Installation

$ npm install generic-hex-dump

API

Dump(length)

Create a new dump for a buffer of total length.

.lines()

Get the number of lines the dump will have.

.slice(buf, line)

Get buf's slice for line.

.offset(line)

Print the offset column for line.

.hex(slice)

Create an array of 2-character hex strings for each byte in slice.

.strings(slice)

Create an array of 1-character strings for each byte in slice, defaulting to . if a byte's value isn't human readable.

.offsetWidth()

Get the width of the offset column.

.printable(v)

Check if character code v is printable. Override this function to change what .strings() replaces with a ..

.replace(from, to)

In the string column, replace character from with to. Either can be a char code or a single character string. If this is defined for a character, the .printable() check will be bypassed.

Example:

Replace all occurences of \r with :

  dump.replace('\r', '␍');

License

MIT

FAQs

Package last updated on 27 Oct 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts