aboutsummaryrefslogtreecommitdiff
path: root/docs/api/utils.md
diff options
context:
space:
mode:
Diffstat (limited to 'docs/api/utils.md')
-rw-r--r--docs/api/utils.md14
1 files changed, 14 insertions, 0 deletions
diff --git a/docs/api/utils.md b/docs/api/utils.md
index cf76769eb..24cb94ed2 100644
--- a/docs/api/utils.md
+++ b/docs/api/utils.md
@@ -486,3 +486,17 @@ To resolve relative to the directory containing the current file, pass `import.m
```ts
Bun.resolveSync("./foo.ts", import.meta.dir);
```
+
+## `serialize` & `deserialize` in `bun:jsc`
+
+To save a JavaScript value into an ArrayBuffer & back, use `serialize` and `deserialize` from the `"bun:jsc"` module.
+
+```js
+import { serialize, deserialize } from "bun:jsc";
+
+const buf = serialize({ foo: "bar" });
+const obj = deserialize(buf);
+console.log(obj); // => { foo: "bar" }
+```
+
+Internally, [`structuredClone`](https://developer.mozilla.org/en-US/docs/Web/API/structuredClone) and [`postMessage`](https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage) serialize and deserialize the same way. This exposes the underlying [HTML Structured Clone Algorithm](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm) to JavaScript as an ArrayBuffer.