From 03ab706e03cdc16ff897e4ab54d87f343a8d61db Mon Sep 17 00:00:00 2001 From: Alex Potsides Date: Fri, 13 Oct 2023 16:34:05 +0300 Subject: [PATCH] fix: write string into output buffer as uint8array (#118) We cannot call `.write` on `buf` as it is a `Uint8Array` not a node buffer --- packages/protons-runtime/src/utils/writer.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/protons-runtime/src/utils/writer.ts b/packages/protons-runtime/src/utils/writer.ts index a2f4cdd..0c0677e 100644 --- a/packages/protons-runtime/src/utils/writer.ts +++ b/packages/protons-runtime/src/utils/writer.ts @@ -1,4 +1,5 @@ import { allocUnsafe } from 'uint8arrays/alloc' +import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' import { writeFloatLE, writeDoubleLE } from './float.js' import { LongBits } from './longbits.js' import pool from './pool.js' @@ -424,8 +425,7 @@ function writeStringBuffer (val: string, buf: Uint8Array, pos: number): void { // @ts-expect-error buf isn't a Uint8Array? buf.utf8Write(val, pos) } else { - // @ts-expect-error .write is a function on node Buffers - buf.write(val, pos) + buf.set(uint8ArrayFromString(val), pos) } }