@andrew_l/tl-pack 0.1.7 → 0.1.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/stream.js DELETED
@@ -1,67 +0,0 @@
1
- import { Transform } from 'stream';
2
- import { BinaryWriter } from './BinaryWriter.js';
3
- import { BinaryReader } from './BinaryReader.js';
4
- import { CORE_TYPES } from './constants.js';
5
- export class TLEncode extends Transform {
6
- writer;
7
- count;
8
- constructor(options) {
9
- const opts = options || {};
10
- opts.streamOptions = { writableObjectMode: true, ...(opts.streamOptions || {}) };
11
- super(opts.streamOptions);
12
- const writer = new BinaryWriter(options);
13
- const customFlush = opts.streamOptions.flush;
14
- const VECTOR_TYPES = new Uint8Array(2);
15
- VECTOR_TYPES[0] = CORE_TYPES.VectorDynamic;
16
- VECTOR_TYPES[1] = CORE_TYPES.None;
17
- // push a byte about dynamic vector starting
18
- this.push(VECTOR_TYPES.subarray(0, 1));
19
- this._flush = (callback) => {
20
- // push a byte about dynamic vector ending
21
- this.push(VECTOR_TYPES.subarray(1, 2));
22
- if (customFlush) {
23
- customFlush.call(this, callback);
24
- }
25
- else {
26
- callback();
27
- }
28
- };
29
- this.writer = writer;
30
- this.count = 0;
31
- }
32
- _transform(chunk, encoding, callback) {
33
- const buff = this.writer.encode(chunk);
34
- this.push(buff);
35
- this.count++;
36
- callback();
37
- }
38
- }
39
- export class TLDecode extends Transform {
40
- reader;
41
- incompleteBuffer;
42
- constructor(options) {
43
- if (!options)
44
- options = {};
45
- options.objectMode = true;
46
- super(options);
47
- this.incompleteBuffer = null;
48
- this.reader = new BinaryReader(new Uint8Array(8192));
49
- }
50
- _transform(chunk, encoding, callback) {
51
- if (this.incompleteBuffer) {
52
- chunk = Buffer.concat([this.incompleteBuffer, chunk]);
53
- this.incompleteBuffer = null;
54
- }
55
- try {
56
- const value = this.reader.decode(chunk);
57
- return callback(null, value);
58
- }
59
- catch (err) {
60
- if (err?.incomplete) {
61
- this.incompleteBuffer = chunk;
62
- return callback();
63
- }
64
- return callback(err);
65
- }
66
- }
67
- }