feat: utf8

This commit is contained in:
TrèsAbhi committed 2024-02-05 18:06:18 -06:00
1 parent 63084d1855
commit 2de077a3ab
3 files changed
+19 -6

No files matched your search

+5 -5
View File
@@ -44,7 +44,7 @@ export class BkonReadStream extends ReadStream {
}
magic() {
const magic = this.ascii(4);
const magic = this.utf8(4);
if (magic !== 'BKON') {
throw new Error(`Invalid Bkon magic number: "${magic}"`);
@@ -100,7 +100,7 @@ export class BkonReadStream extends ReadStream {
string() {
const length = this.uint32();
const string = this.ascii(length);
const string = this.utf8(length);
return string;
}
@@ -332,11 +332,11 @@ export class BkonWriteStream extends WriteStream {
}
string(value: string) {
this.uint32(value.length);
this.ascii(value);
this.uint32(Buffer.byteLength(value));
this.utf8(value);
}
magic() {
this.ascii('BKON');
this.utf8('BKON');
}
}
+13
View File
@@ -35,6 +35,9 @@ export class ReadStream {
ascii(size: number) {
return this.buffer.toString('ascii', this.increment(size), this.index);
}
utf8(size: number) {
return this.buffer.toString('utf8', this.increment(size), this.index);
}
int8() {
return this.buffer.readInt8(this.increment(1));
@@ -94,6 +97,16 @@ export class WriteStream {
}
return this;
}
utf8(value: string) {
const buffer = Buffer.alloc(Buffer.byteLength(value));
buffer.write(value, 'utf8');
buffer.forEach((value) => {
this.array.push(value);
});
return this;
}
private uintN(bytes: number, value: number) {
for (let index = 0; index < bytes; index++) {