Skip to content

jcbhmr/legacy-text-encoder

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Legacy TextEncoder

🔎 A TextEncoder that supports the legacy (non-UTF-8) encodings

Installation

npm install @jcbhmr/legacy-text-encoder

Usage

This package exposes

import { LegacyTextEncoder } from "@jcbhmr/legacy-text-encoder";

const encoder = new LegacyTextEncoder("utf-16le");
const bytes = encoder.encode("Hi!");
console.log(bytes);
// Output:
// Uint8Array [ 0x48, 0x00, 0x69, 0x00, 0x21, 0x00 ]
import { LegacyTextEncoderStream } from "@jcbhmr/legacy-text-encoder";

const encoder = new LegacyTextEncoderStream("utf-16le");
await ReadableStream.from(["Hi", "!"])
  .pipeThrough(encoder)
  .pipeTo(
    new WritableStream({
      write(chunk) {
        console.log(chunk);
      },
    }),
  );
// Output:
// Uint8Array [ 0x48, 0x00, 0x69, 0x00 ]
// Uint8Array [ 0x21, 0x00 ]

Development

using scalarValues = source[Symbol.iterator]();
const bytes = Uint8Array.from(source.flatMap(encoding.createEncoder()));

About

🔎 A TextEncoder that supports the legacy (non-UTF-8) encodings

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors