0.0.7 ā€¢ Published 2 years ago

ts-coder v0.0.7

Weekly downloads
9
License
MIT
Repository
github
Last release
2 years ago

ts-coder-thumbnail

simple ts encoding/decoding library

ā–¶ About

ts-coder is a simple ts(transport streaming) file encoding and decoding library.

ts-coder-encoding-and-decoding

āž• Installation

ts-coder can be installed using npm.

yarn add ts-coder # or npm install ts-coder

šŸ’” How to use

data ā–¶ ts packets

import { Encoder } from 'ts-coder'

const encoder = new Encoder({
  pid: 0x30, // packet identifier
})

const packets = encoder.encode(Buffer.from('hello world')) // encode "hello world" to ts packets
console.log(packets)

data ā—€ ts packets

import { Encoder, Decoder } from 'ts-coder'

// Encode part.

const encoder = new Encoder({
  pid: 0x30,
  headSize: 4,
  preMap(buffer, index, buffers) {
    let status = 0x00

    if (index === buffers.length - 1) {
      status = 0x01
    }

    return Buffer.concat([Buffer.from([status, 0x00, 0x00, 0x00]), buffer])
  },
})

const packets = encoder.encode(Buffer.from("hello world"))

// Decode part.

const decoder = new Decoder({
  eadSize: 4,
  isEnd(head) {
    return head[0] === 0x01
  },
})

decoder.onData((buffer) => {
  console.log(buffer) // buffer with "hello world" string
})

for (const packet of packets) {
  decoder.push(packet)
}
0.0.7

2 years ago

0.0.6

3 years ago

0.0.5

3 years ago

0.0.4

3 years ago

0.0.3

3 years ago

0.0.1

3 years ago

0.0.2

3 years ago

0.0.0

3 years ago