Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
};
```

Expand Down
7 changes: 6 additions & 1 deletion build.json
Original file line number Diff line number Diff line change
@@ -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"
]
}
8 changes: 5 additions & 3 deletions metacom.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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`);
Expand All @@ -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 };
};
Expand Down