Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

bytestreamjs

Package Overview
Dependencies
Maintainers
2
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bytestreamjs

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

  • 2.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
86K
increased by0.24%
Maintainers
2
Weekly downloads
 
Created
Source

ByteStream.js

License Test 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.

MethodDescription
clearClear existing stream
fromArrayBufferInitialize "Stream" object from existing "ArrayBuffer"
fromUint8ArrayInitialize "Stream" object from existing "Uint8Array"
fromStringInitialize "Stream" object from existing string
toStringRepresent "Stream" object content as a string
fromHexStringInitialize "Stream" object from existing hexdecimal string
toHexStringRepresent "Stream" object content as a hexdecimal string
copyReturn copy of existing "Stream"
sliceReturn slice of existing "Stream"
reallocChange size of existing "Stream"
appendAppend a new "Stream" content to the current "Stream"
insertInsert "Stream" content to the current "Stream" at specific position
isEqualCheck that two "Stream" objects has equal content
isEqualViewCheck that current "Stream" objects has equal content with input "Uint8Array"
findPatternFind any byte pattern in "Stream"
findFirstInFind first position of any pattern from input array
findAllInFind all positions of any pattern from input array
findAllPatternInFind all positions of a pattern
findFirstNotInFind first position of data, not included in patterns from input array
findAllNotInFind all positions of data, not included in patterns from input array
findFirstSequenceFind position of a sequence of any patterns from input array
findAllSequencesFind all positions of a sequence of any patterns from input array
findPairedPatternsFind all paired patterns in the stream
findPairedArraysFind all paired patterns in the stream
replacePatternReplace one patter with other
skipPatternsSkip any pattern from input array
skipNotPatternsSkip any pattern not from input array

SeqStream class

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

MethodDescription
resetPositionReset current position of the "SeqStream"
findPatternFind any byte pattern in "ByteStream"
findFirstInFind first position of any pattern from input array
findAllInFind all positions of any pattern from input array
findFirstNotInFind first position of data, not included in patterns from input array
findAllNotInFind all positions of data, not included in patterns from input array
findFirstSequenceFind position of a sequence of any patterns from input array
findAllSequencesFind position of a sequence of any patterns from input array
findPairedPatternsFind all paired patterns in the stream
findPairedArraysFind all paired patterns in the stream
replacePatternReplace one patter with other
skipPatternsSkip of any pattern from input array
skipNotPatternsSkip of any pattern from input array
appendAppend a new "Stream" content to the current "Stream"
appendViewAppend a "view" content to the current "Stream"
appendCharAppend a new char to the current "Stream"
getBlockGet a block of data
getUint32Get 4-byte unsigned integer value

BitStream class

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

MethodDescription
clearClear existing stream
fromByteStreamInitialize "BitStream" by data from existing "ByteStream"
fromArrayBufferInitialize "BitStream" object from existing "ArrayBuffer"
fromUint8ArrayInitialize "BitStream" object from existing "Uint8Array"
fromStringInitialize "BitStream" object from existing bit string
toStringRepresent "BitStream" object content as a string
shiftRightShift entire "BitStream" value right to number of bits
shiftLeftShift entire "BitStream" value left to number of bits
sliceReturn slice of existing "BitStream"
copyReturn copy of existing "BitStream"
shrinkShrink unnecessary bytes in current stream accordingly to "bitsCount" value
reverseBytesReverse bits order in each byte in the stream
reverseValueReverse all bits in entire "BitStream"
getNumberValueTrying to represent entire "BitStream" as an unsigned integer
findPatternFind any bit pattern in "BitStream"
findFirstInFind first position of any pattern from input array
findAllInFind all positions of any pattern from input array
findAllPatternInFind all positions of a pattern
findFirstNotInFind first position of data, not included in patterns from input array
findAllNotInFind all positions of data, not included in patterns from input array
findFirstSequenceFind position of a sequence of any patterns from input array
findAllSequencesFind position of a sequence of any patterns from input array
findPairedPatternsFind all paired patterns in the stream
findPairedArraysFind all paired patterns in the stream
replacePatternReplace one pattern with other
skipPatternsSkip any pattern from input array
skipNotPatternsSkip any pattern not from input array
appendAppend 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.

MethodDescription
getBitsGet next "length" bits from the stream
getBitsStringGet string representation for the next "length" bits from the stream
getBitsReversedValueGet number value representation of the next "length" bits from the stream, preliminary reversed
toStringRepresent 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-2022, 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.

Keywords

FAQs

Package last updated on 20 May 2022

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc