Skip to content

Commit 5b3fcd1

Browse files
authored
Remove buffer-builder dependency (#416)
The buffer-builder dependency has not been updated in 11 years. That might be fine as it doesn't do a whole lot, but we're not using much of it anyway, and it does use a deprecated API (although it does so safely).
1 parent a0172ee commit 5b3fcd1

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

lib/src/packet-transformer.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
import {Observable, Subject} from 'rxjs';
66
import {mergeMap} from 'rxjs/operators';
7-
import BufferBuilder = require('buffer-builder');
87

98
/**
109
* Decodes arbitrarily-chunked buffers, for example
@@ -57,18 +56,20 @@ export class PacketTransformer {
5756

5857
// Write the length in varint format, 7 bits at a time from least to most
5958
// significant.
60-
const header = new BufferBuilder(8);
59+
const header = Buffer.alloc(8);
60+
let offset = 0;
6161
while (length > 0) {
6262
// The highest-order bit indicates whether more bytes are necessary to
6363
// fully express the number. The lower 7 bits indicate the number's
6464
// value.
65-
header.appendUInt8((length > 0x7f ? 0x80 : 0) | (length & 0x7f));
65+
header.writeUInt8((length > 0x7f ? 0x80 : 0) | (length & 0x7f), offset);
66+
offset++;
6667
length >>= 7;
6768
}
6869

69-
const packet = Buffer.alloc(header.length + protobuf.length);
70-
header.copy(packet);
71-
packet.set(protobuf, header.length);
70+
const packet = Buffer.alloc(offset + protobuf.length);
71+
header.copy(packet, 0, 0, offset);
72+
packet.set(protobuf, offset);
7273
this.writeInboundBuffer(packet);
7374
} catch (error) {
7475
this.outboundProtobufsInternal$.error(error);

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@
6262
},
6363
"dependencies": {
6464
"@bufbuild/protobuf": "^2.5.0",
65-
"buffer-builder": "^0.2.0",
6665
"colorjs.io": "^0.5.0",
6766
"immutable": "^5.0.2",
6867
"rxjs": "^7.4.0",

0 commit comments

Comments
 (0)