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

@penneo/bytestreamjs

v1.0.23

Published

ByteStream is a library making possibe to manipulates single bytes and bits on pure JavaScript

Downloads

29

Readme

ByteStream.js

License CircleCI Known Vulnerabilities Coverage Status

ByteStream class

ByteStream class is the major class for all others. It provides many useful function for making search for patterns and data transformation. Optimized for fast as possible data processing.

Method | Description -------|-------------- clear|Clear existing stream fromArrayBuffer|Initialize "Stream" object from existing "ArrayBuffer" fromUint8Array|Initialize "Stream" object from existing "Uint8Array" fromString|Initialize "Stream" object from existing string toString|Represent "Stream" object content as a string fromHexString|Initialize "Stream" object from existing hexdecimal string toHexString|Represent "Stream" object content as a hexdecimal string copy|Return copy of existing "Stream" slice|Return slice of existing "Stream" realloc|Change size of existing "Stream" append|Append a new "Stream" content to the current "Stream" insert|Insert "Stream" content to the current "Stream" at specific position isEqual|Check that two "Stream" objects has equal content isEqualView|Check that current "Stream" objects has equal content with input "Uint8Array" findPattern|Find any byte pattern in "Stream" findFirstIn|Find first position of any pattern from input array findAllIn|Find all positions of any pattern from input array findAllPatternIn|Find all positions of a pattern findFirstNotIn|Find first position of data, not included in patterns from input array findAllNotIn|Find all positions of data, not included in patterns from input array findFirstSequence|Find position of a sequence of any patterns from input array findAllSequences|Find all positions of a sequence of any patterns from input array findPairedPatterns|Find all paired patterns in the stream findPairedArrays|Find all paired patterns in the stream replacePattern|Replace one patter with other skipPatterns|Skip any pattern from input array skipNotPatterns|Skip any pattern not from input array

SeqStream class

SeqStream class is the aux class for sequential reading/writing data from/to ByteStream underline class.

Method | Description -------|-------------- resetPosition|Reset current position of the "SeqStream" findPattern|Find any byte pattern in "ByteStream" findFirstIn|Find first position of any pattern from input array findAllIn|Find all positions of any pattern from input array findFirstNotIn|Find first position of data, not included in patterns from input array findAllNotIn|Find all positions of data, not included in patterns from input array findFirstSequence|Find position of a sequence of any patterns from input array findAllSequences|Find position of a sequence of any patterns from input array findPairedPatterns|Find all paired patterns in the stream findPairedArrays|Find all paired patterns in the stream replacePattern|Replace one patter with other skipPatterns|Skip of any pattern from input array skipNotPatterns|Skip of any pattern from input array append|Append a new "Stream" content to the current "Stream" appendView|Append a "view" content to the current "Stream" appendChar|Append a new char to the current "Stream" getBlock|Get a block of data getUint32|Get 4-byte unsigned integer value

BitStream class

Main purpose of the BitStream is manipulating of each bit inside any ByteStream data.

Method | Description -------|-------------- clear|Clear existing stream fromByteStream|Initialize "BitStream" by data from existing "ByteStream" fromArrayBuffer|Initialize "BitStream" object from existing "ArrayBuffer" fromUint8Array|Initialize "BitStream" object from existing "Uint8Array" fromString|Initialize "BitStream" object from existing bit string toString|Represent "BitStream" object content as a string shiftRight|Shift entire "BitStream" value right to number of bits shiftLeft|Shift entire "BitStream" value left to number of bits slice|Return slice of existing "BitStream" copy|Return copy of existing "BitStream" shrink|Shrink unnecessary bytes in current stream accordingly to "bitsCount" value reverseBytes|Reverse bits order in each byte in the stream reverseValue|Reverse all bits in entire "BitStream" getNumberValue|Trying to represent entire "BitStream" as an unsigned integer findPattern|Find any bit pattern in "BitStream" findFirstIn|Find first position of any pattern from input array findAllIn|Find all positions of any pattern from input array findAllPatternIn|Find all positions of a pattern findFirstNotIn|Find first position of data, not included in patterns from input array findAllNotIn|Find all positions of data, not included in patterns from input array findFirstSequence|Find position of a sequence of any patterns from input array findAllSequences|Find position of a sequence of any patterns from input array findPairedPatterns|Find all paired patterns in the stream findPairedArrays|Find all paired patterns in the stream replacePattern|Replace one pattern with other skipPatterns|Skip any pattern from input array skipNotPatterns|Skip any pattern not from input array append|Append a new "BitStream" content to the current "BitStream"

SeqBitStream class

SeqBitStream class is the aux class for sequential reading/writing data from/to BitStream underline class.

Method | Description -------|-------------- getBits|Get next "length" bits from the stream getBitsString|Get string representation for the next "length" bits from the stream getBitsReversedValue|Get number value representation of the next "length" bits from the stream, preliminary reversed toString|Represent remaining bits in "BitStream" as a string

parseByteMap functionality

The parseByteMap function is intended to parse and check byte streams with determinated structure.

Example of map used as a kind of template. Exactly this map is using for parsing PDF xref table:

let map = [
	{
		type: "string",
		name: "type",
		minlength: 1,
		maxlength: 1,
		func: function(array){
			let result = {
				status: (-1),
				length: 1
			};
			
			switch(array[0])
			{
				case 0x6E: // "n"
					result.value = "n";
					break;
				case 0x66: // "f"
					result.value = "f";
					break;
				default:
					return result;
			}
			
			result.status = 1;
			
			return result;
		}
	},
	{
		type: "check",
		minlength: 1,
		maxlength: 2,
		func: function(array){
			let position = (-1);
			
			if(array[0] == 0x0A)
				position = 1;
			if(array[1] == 0x0A)
				position = 2;
			
			return {
				status: (position > 0) ? 1 : (-1),
				length: position
			};
		}
	}
];

License

Copyright (c) 2016-2018, Peculiar Ventures All rights reserved.

Author 2016-2018 Yury Strozhevsky.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

  3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.