npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

stream-data-view

v1.7.2

Published

Easily work with data bytes like a pro.

Downloads

462

Readme

Version MIT License

StreamDataView

Easy work with data bytes like a pro. For NodeJS and Browser.

A well tested and documented library for byte handling. Written in TypeScript, compiled with declarations types. The documentation also works great with JavaScript.

Features

  • View array buffer.
  • Convert data types. (signed, unsigned, strings, utf-8)
  • Read / write in a stream without worring about the byte offset.
  • Little or big endian. Automatically handled.

Use Case

  • Read and parse binary files.
  • Work with communication protocols like CAN.
  • Use it for container files.
  • Just display a buffer in pretty print.
  • Simply convert between numbers, strings and byte arrays (buffer).
  • Generate and parse your custom binary files for import and export.

Documentation

I recommend to use TypeScript. This library has a documented declaration file.

API Docs

Installation

npm i stream-data-view

NPM Package

Quick Guide

// Create a stream and write some data.
let stream = new StreamDataView(8);
stream.setNextInt32(123456);
stream.setNextUint8(42);

// Get the byte data as pretty print.
console.log(stream.toByteString());

// Read any buffer.
let buffer = stream.getBuffer();
let read = new StreamDataView(buffer);

console.log('INT32 ', read.getNextInt32());
console.log('UINT8 ', read.getNextUint8());
// Prints 'Awesome' to the browser console.
console.log(StreamDataView.fromByteString('41 77 65 73 6F 6D 65').toTextString());

In NodeJS e.g.

const StreamDataView = require('stream-data-view').StreamDataView;
const stream = new StreamDataView(4);
stream.setNextUint32(0x12345678);
console.log(stream.toByteString());

You can also use a dynamic length of StreamDataView, just omit the argument.

const stream = new StreamDataView();
stream.setNextString('Hello');
stream.setNextString(' ');
stream.setNextString('World');
// Buffer length is now: 11 byte.
console.log(stream.getBuffer());

You can also resize manually.

const stream = new StreamDataView(1);
stream.setNextUint8(0x4c);
// Stream buffer length is: 1 byte "L"
stream.resize(3);
stream.setNextUint8(0x4f);
stream.setNextUint8(0x4c);
// Stream buffer length is: 3 byte "LOL"
console.log(stream.toTextString());

Crop buffer by offset position.

const stream = new StreamDataView(42);
stream.setNextString('Hello World');
// Stream buffer length is: 42 "Hello World..."
stream.crop();
// Stream buffer length is: 11 "Hello World"
console.log(stream.toTextString());

Dependencies

Just JavaScript. But expected ES6 (ES2015). Your browser should support DataView.

Contribution

Any feedback like issues about bugs, feature-requests and project setup is welcome.

Build

Install packages.

npm i

Build to dist.

npm run build

Format the source code.

npm run format

Run linter.

npm run lint

Run unit tests.

npm run test

License

MIT © Copyright 2018 - 2021 Dominik Geng (@domske)