Remove all direct usages of Buffer so that it can be decided based on platform.
This commit is contained in:
parent
a157685fcc
commit
dd46ec825b
2 changed files with 13 additions and 12 deletions
|
@ -23,20 +23,20 @@ export class WriterBase {
|
|||
}
|
||||
|
||||
public writeBuffer(buffer:Buffer) {
|
||||
this.buffer = Buffer.concat([this.buffer, buffer], this.buffer.length + buffer.length);
|
||||
this.buffer = getBufferClass().concat([this.buffer, buffer], this.buffer.length + buffer.length);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public writeUint8Array(array:Uint8Array) {
|
||||
this.writeBuffer(Buffer.from(array));
|
||||
this.writeBuffer(getBufferClass().from(array));
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public writeByte(value:number) {
|
||||
if (this.resizable) {
|
||||
const buffer = Buffer.alloc(1);
|
||||
const buffer = getBufferClass().alloc(1);
|
||||
buffer.writeInt8(value);
|
||||
this.writeBuffer(buffer);
|
||||
} else {
|
||||
|
@ -49,7 +49,7 @@ export class WriterBase {
|
|||
|
||||
public writeUByte(value:number) {
|
||||
if (this.resizable) {
|
||||
const buffer = Buffer.alloc(1);
|
||||
const buffer = getBufferClass().alloc(1);
|
||||
buffer.writeUInt8(value);
|
||||
this.writeBuffer(buffer);
|
||||
} else {
|
||||
|
|
|
@ -3,11 +3,12 @@
|
|||
|
||||
import { IWriter } from "./IWriter";
|
||||
import { WriterBase } from "../base/WriterBase";
|
||||
import { getBufferClass } from "../base/BufferShim";
|
||||
|
||||
export class WriterLE extends WriterBase implements IWriter {
|
||||
public writeShort(value:number) {
|
||||
if (this.resizable) {
|
||||
const buffer = Buffer.alloc(2);
|
||||
const buffer = getBufferClass().alloc(2);
|
||||
buffer.writeInt16LE(value);
|
||||
this.writeBuffer(buffer);
|
||||
} else {
|
||||
|
@ -20,7 +21,7 @@ export class WriterLE extends WriterBase implements IWriter {
|
|||
|
||||
public writeUShort(value:number) {
|
||||
if (this.resizable) {
|
||||
const buffer = Buffer.alloc(2);
|
||||
const buffer = getBufferClass().alloc(2);
|
||||
buffer.writeUInt16LE(value);
|
||||
this.writeBuffer(buffer);
|
||||
} else {
|
||||
|
@ -33,7 +34,7 @@ export class WriterLE extends WriterBase implements IWriter {
|
|||
|
||||
public writeInt(value:number) {
|
||||
if (this.resizable) {
|
||||
const buffer = Buffer.alloc(4);
|
||||
const buffer = getBufferClass().alloc(4);
|
||||
buffer.writeInt32LE(value);
|
||||
this.writeBuffer(buffer);
|
||||
} else {
|
||||
|
@ -45,7 +46,7 @@ export class WriterLE extends WriterBase implements IWriter {
|
|||
}
|
||||
public writeUInt(value:number) {
|
||||
if (this.resizable) {
|
||||
const buffer = Buffer.alloc(4);
|
||||
const buffer = getBufferClass().alloc(4);
|
||||
buffer.writeUInt32LE(value);
|
||||
this.writeBuffer(buffer);
|
||||
} else {
|
||||
|
@ -62,7 +63,7 @@ export class WriterLE extends WriterBase implements IWriter {
|
|||
}
|
||||
|
||||
if (this.resizable) {
|
||||
const buffer = Buffer.alloc(8);
|
||||
const buffer = getBufferClass().alloc(8);
|
||||
buffer.writeBigInt64LE(value);
|
||||
this.writeBuffer(buffer);
|
||||
} else {
|
||||
|
@ -79,7 +80,7 @@ export class WriterLE extends WriterBase implements IWriter {
|
|||
}
|
||||
|
||||
if (this.resizable) {
|
||||
const buffer = Buffer.alloc(8);
|
||||
const buffer = getBufferClass().alloc(8);
|
||||
buffer.writeBigUint64LE(value);
|
||||
this.writeBuffer(buffer);
|
||||
} else {
|
||||
|
@ -92,7 +93,7 @@ export class WriterLE extends WriterBase implements IWriter {
|
|||
|
||||
public writeFloat(value:number) {
|
||||
if (this.resizable) {
|
||||
const buffer = Buffer.alloc(4);
|
||||
const buffer = getBufferClass().alloc(4);
|
||||
buffer.writeFloatLE(value);
|
||||
this.writeBuffer(buffer);
|
||||
} else {
|
||||
|
@ -105,7 +106,7 @@ export class WriterLE extends WriterBase implements IWriter {
|
|||
|
||||
public writeDouble(value:number) {
|
||||
if (this.resizable) {
|
||||
const buffer = Buffer.alloc(8);
|
||||
const buffer = getBufferClass().alloc(8);
|
||||
buffer.writeDoubleLE(value);
|
||||
this.writeBuffer(buffer);
|
||||
} else {
|
||||
|
|
Loading…
Reference in a new issue