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

byte-encoder

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

byte-encoder

Encode data to utf8 bytes. Browser or NodeJS.

  • 1.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
decreased by-87.5%
Maintainers
1
Weekly downloads
 
Created
Source

ByteEncoder

JavaScript Style Guide

Encode data to utf8 bytes. Browser or NodeJS.


Table of Contents


Install

npm i byte-encoder 

Usage

static (class) ByteEncoder.Iterator:

Args [string: string]

import ByteView from 'byteview'
import ByteEncoder from 'byte-encoder'

const chunks = []

for (const chunk of new ByteEncoder.Iterator('Hello World!')) {
  chunks.push(chunk)
}

console.log(ByteView.from(chunks))
// prints: ByteView(12) [72, 101, 108, 108, 111, 32,  87, 111, 114, 108, 100, 33]

(method) ByteEncoder.encode:

Args [string: string]

import ByteEncoder from 'byte-encoder'

const byteEncoder = new ByteEncoder()

console.log(byteEncoder.encode('Hello World!'))
// prints: ByteView(12) [72, 101, 108, 108, 111, 32,  87, 111, 114, 108, 100, 33]

(method) ByteEncoder.encodeInto:

Args [string: string, byteView: ByteView | Buffer | ArrayBufferView]

import ByteEncoder from 'byte-encoder'

const byteEncoder = new ByteEncoder()
const byteView = ByteView.alloc(12)

console.log(byteView)
// prints: ByteView(12) [00, 00, 00, 00, 00, 00,  00, 00, 00, 00, 00, 00]

console.log(byteEncoder.encodeInto('Hello World!', byteView))
// prints: { read: 12, written: 12 }

console.log(byteView)
// prints: ByteView(12) [72, 101, 108, 108, 111, 32,  87, 111, 114, 108, 100, 33]

(method) ByteEncoder.encodeToBuffer:

Args [string: string]

import ByteEncoder from 'byte-encoder'

const byteEncoder = new ByteEncoder()

console.log(byteEncoder.encodeToBuffer('Hello World!'))
// prints: ArrayBuffer { [Uint8Contents]: <48 65 6c 6c 6f 20 57 6f 72 6c 64 21>, byteLength: 12 }

Keywords

FAQs

Package last updated on 11 Oct 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