Skip to content

Commit

Permalink
chore: slice -> subarray
Browse files Browse the repository at this point in the history
  • Loading branch information
maraisr committed May 17, 2023
1 parent 3434236 commit 68a58a2
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/node.ts
Expand Up @@ -32,8 +32,8 @@ async function* generate<T>(

payloads = [];
while (!!~idx_boundary) {
const current = buffer.slice(0, idx_boundary);
const next = buffer.slice(idx_boundary + len_boundary);
const current = buffer.subarray(0, idx_boundary);
const next = buffer.subarray(idx_boundary + len_boundary);

if (is_preamble) {
is_preamble = false;
Expand All @@ -42,7 +42,7 @@ async function* generate<T>(
} else {
const headers: Record<string, string> = {};
const idx_headers = current.indexOf('\r\n\r\n') + 4; // 4 -> '\r\n\r\n'.length
const arr_headers = String(buffer.slice(0, idx_headers))
const arr_headers = String(buffer.subarray(0, idx_headers))
.trim()
.split('\r\n');

Expand All @@ -55,7 +55,7 @@ async function* generate<T>(

const last_idx = current.lastIndexOf('\r\n', idx_headers);

let body: T | Buffer = current.slice(idx_headers, last_idx > -1 ? undefined : last_idx);
let body: T | Buffer = current.subarray(idx_headers, last_idx > -1 ? undefined : last_idx);
let is_json = false;

tmp = headers['content-type'];
Expand Down

0 comments on commit 68a58a2

Please sign in to comment.