Skip to content

Commit 28db260

Browse files
committed
🐛 fix: allocate capacities in string encoding
1 parent 2de410b commit 28db260

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

src/bencode/BencodeEncoder.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ export class BencodeEncoder implements BinaryJsonEncoder {
113113
const length = utf8Size(str);
114114
writer.ascii(length + '');
115115
writer.u8(0x3a); // ':'
116-
writer.ensureCapacity(length);
116+
writer.ensureCapacity(str.length * 4);
117117
writer.utf8(str);
118118
}
119119

src/ion/IonEncoderFast.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ export class IonEncoderFast {
182182
writer.u8(TYPE_OVERLAY.STRI + 14);
183183
this.writeVUint(length);
184184
}
185+
writer.ensureCapacity(length * 4);
185186
writer.utf8(str);
186187
}
187188

0 commit comments

Comments
 (0)