diff --git a/README.md b/README.md index fe4814e1..f342d699 100644 --- a/README.md +++ b/README.md @@ -96,7 +96,7 @@ async ({ name }) => { const writable = context.client.createStream(name, size); // Pipe nodejs readable to metacom writable readable.pipe(writable); - return { streamId: writable.streamId }; + return { streamId: writable.id }; }; ``` diff --git a/build.json b/build.json index f5c90cb7..13c334bd 100644 --- a/build.json +++ b/build.json @@ -1,3 +1,8 @@ { - "order": ["client-listeners.js", "chunks.js", "streams.js", "metacom.js"] + "order": [ + "client-listeners.js", + "chunks-browser.js", + "streams.js", + "metacom.js" + ] } diff --git a/metacom.mjs b/metacom.mjs index b9cadbfb..2ae7e11f 100644 --- a/metacom.mjs +++ b/metacom.mjs @@ -20,10 +20,11 @@ const listenOnline = (connections) => { export { listenOnline }; //#endregion -//#region chunks.js +//#region chunks-browser.js const ID_LENGTH_BYTES = 1; const chunkEncode = (id, payload) => { - const idBuffer = Buffer.from(id, 'utf8'); + const encoder = new TextEncoder(); + const idBuffer = encoder.encode(id); const idLength = idBuffer.length; if (idLength > 255) { throw new Error(`ID length ${idLength} exceeds maximum of 255 characters`); @@ -37,7 +38,8 @@ const chunkEncode = (id, payload) => { const chunkDecode = (chunk) => { const idLength = chunk[0]; const idBuffer = chunk.subarray(ID_LENGTH_BYTES, ID_LENGTH_BYTES + idLength); - const id = Buffer.from(idBuffer).toString('utf8'); + const decoder = new TextDecoder(); + const id = decoder.decode(idBuffer); const payload = chunk.subarray(ID_LENGTH_BYTES + idLength); return { id, payload }; };