Replace Buffer with Uint8Array
This commit is contained in:
parent
8d654bfee2
commit
8eef231d69
@ -92,11 +92,11 @@ export class HttpServer implements IServer
|
||||
|
||||
private handlePost(req: IncomingMessage, res: ServerResponse, service: Service): void
|
||||
{
|
||||
let data = Buffer.from("");
|
||||
let data = new Uint8Array();
|
||||
|
||||
req.on("data", (chunk: Buffer) =>
|
||||
req.on("data", (chunk: Uint8Array) =>
|
||||
{
|
||||
data = Buffer.concat([data, chunk]);
|
||||
data = new Uint8Array([ ...data, ...chunk ]);
|
||||
});
|
||||
|
||||
req.on("end", () =>
|
||||
@ -114,7 +114,7 @@ export class HttpServer implements IServer
|
||||
|
||||
export class Service
|
||||
{
|
||||
protected send(res: ServerResponse, data: Buffer, type: string, compress: boolean = true): void
|
||||
protected send(res: ServerResponse, data: Uint8Array, type: string, compress: boolean = true): void
|
||||
{
|
||||
const bytes = (compress) ? Zlib.compress(data) : data;
|
||||
const headers = {
|
||||
@ -127,7 +127,7 @@ export class Service
|
||||
|
||||
protected sendJson(res: ServerResponse, data: string, compress: boolean = true): void
|
||||
{
|
||||
const bytes = Buffer.from(data);
|
||||
const bytes = new TextEncoder().encode(data);
|
||||
this.send(res, bytes, "json", compress);
|
||||
}
|
||||
|
||||
@ -212,7 +212,7 @@ export class WsServer implements IServer
|
||||
public canSendMessage(url: string)
|
||||
{
|
||||
const ws = this.clients[url];
|
||||
return (!ws) ? false : ws.readyState == WebSocket.OPEN;
|
||||
return (!ws) ? false : (ws.readyState == WebSocket.OPEN);
|
||||
}
|
||||
|
||||
private close(ws: WebSocket): void
|
||||
|
@ -37,7 +37,7 @@ export class Vfs
|
||||
return readFileSync(filepath);
|
||||
}
|
||||
|
||||
public static writeFile(filepath: string, data: Buffer | string, append: boolean = false): void
|
||||
public static writeFile(filepath: string, data: Uint8Array | string, append: boolean = false): void
|
||||
{
|
||||
if (!Vfs.exists(filepath))
|
||||
{
|
||||
@ -94,17 +94,17 @@ export class Log
|
||||
|
||||
export class Zlib
|
||||
{
|
||||
public static compress(data: Buffer): Buffer
|
||||
public static compress(data: Uint8Array, level: number = 9): Uint8Array
|
||||
{
|
||||
return deflateSync(data);
|
||||
return deflateSync(data, { "level": level });
|
||||
}
|
||||
|
||||
public static decompress(data: Buffer): Buffer
|
||||
public static decompress(data: Uint8Array): Uint8Array
|
||||
{
|
||||
return inflateSync(data);
|
||||
}
|
||||
|
||||
public static isCompressed(data: Buffer): boolean
|
||||
public static isCompressed(data: Uint8Array): boolean
|
||||
{
|
||||
// Level | CM/CI FLG
|
||||
// ----- | ---------
|
||||
|
Loading…
x
Reference in New Issue
Block a user