found some more cases of direct Buffer usages

This commit is contained in:
Holly Stubbs 2023-10-24 17:05:20 +01:00
parent 242b3f512b
commit 24f26db2c1

View file

@ -3,11 +3,12 @@
import { IWriter } from "./IWriter"; import { IWriter } from "./IWriter";
import { WriterBase } from "../base/WriterBase"; import { WriterBase } from "../base/WriterBase";
import { getBufferClass } from "../base/BufferShim";
export class WriterBE extends WriterBase implements IWriter { export class WriterBE extends WriterBase implements IWriter {
public writeShort(value:number) { public writeShort(value:number) {
if (this.resizable) { if (this.resizable) {
const buffer = Buffer.alloc(2); const buffer = getBufferClass().alloc(2);
buffer.writeInt16BE(value); buffer.writeInt16BE(value);
this.writeBuffer(buffer); this.writeBuffer(buffer);
} else { } else {
@ -20,7 +21,7 @@ export class WriterBE extends WriterBase implements IWriter {
public writeUShort(value:number) { public writeUShort(value:number) {
if (this.resizable) { if (this.resizable) {
const buffer = Buffer.alloc(2); const buffer = getBufferClass().alloc(2);
buffer.writeUInt16BE(value); buffer.writeUInt16BE(value);
this.writeBuffer(buffer); this.writeBuffer(buffer);
} else { } else {
@ -33,7 +34,7 @@ export class WriterBE extends WriterBase implements IWriter {
public writeInt(value:number) { public writeInt(value:number) {
if (this.resizable) { if (this.resizable) {
const buffer = Buffer.alloc(4); const buffer = getBufferClass().alloc(4);
buffer.writeInt32BE(value); buffer.writeInt32BE(value);
this.writeBuffer(buffer); this.writeBuffer(buffer);
} else { } else {
@ -46,7 +47,7 @@ export class WriterBE extends WriterBase implements IWriter {
public writeUInt(value:number) { public writeUInt(value:number) {
if (this.resizable) { if (this.resizable) {
const buffer = Buffer.alloc(4); const buffer = getBufferClass().alloc(4);
buffer.writeUInt32BE(value); buffer.writeUInt32BE(value);
this.writeBuffer(buffer); this.writeBuffer(buffer);
} else { } else {
@ -63,7 +64,7 @@ export class WriterBE extends WriterBase implements IWriter {
} }
if (this.resizable) { if (this.resizable) {
const buffer = Buffer.alloc(8); const buffer = getBufferClass().alloc(8);
buffer.writeBigInt64BE(value); buffer.writeBigInt64BE(value);
this.writeBuffer(buffer); this.writeBuffer(buffer);
} else { } else {
@ -80,7 +81,7 @@ export class WriterBE extends WriterBase implements IWriter {
} }
if (this.resizable) { if (this.resizable) {
const buffer = Buffer.alloc(8); const buffer = getBufferClass().alloc(8);
buffer.writeBigUint64BE(value); buffer.writeBigUint64BE(value);
this.writeBuffer(buffer); this.writeBuffer(buffer);
} else { } else {
@ -93,7 +94,7 @@ export class WriterBE extends WriterBase implements IWriter {
public writeFloat(value:number) { public writeFloat(value:number) {
if (this.resizable) { if (this.resizable) {
const buffer = Buffer.alloc(4); const buffer = getBufferClass().alloc(4);
buffer.writeFloatBE(value); buffer.writeFloatBE(value);
this.writeBuffer(buffer); this.writeBuffer(buffer);
} else { } else {
@ -106,7 +107,7 @@ export class WriterBE extends WriterBase implements IWriter {
public writeDouble(value:number) { public writeDouble(value:number) {
if (this.resizable) { if (this.resizable) {
const buffer = Buffer.alloc(8); const buffer = getBufferClass().alloc(8);
buffer.writeDoubleBE(value); buffer.writeDoubleBE(value);
this.writeBuffer(buffer); this.writeBuffer(buffer);
} else { } else {