aboutsummaryrefslogtreecommitdiff
path: root/docs/api
diff options
context:
space:
mode:
Diffstat (limited to 'docs/api')
-rw-r--r--docs/api/ffi.md21
-rw-r--r--docs/api/hashing.md4
-rw-r--r--docs/api/http.md8
-rw-r--r--docs/api/spawn.md22
-rw-r--r--docs/api/tcp.md8
-rw-r--r--docs/api/utils.md6
-rw-r--r--docs/api/websockets.md12
-rw-r--r--docs/api/workers.md2
8 files changed, 47 insertions, 36 deletions
diff --git a/docs/api/ffi.md b/docs/api/ffi.md
index d6ed23f47..0beae1744 100644
--- a/docs/api/ffi.md
+++ b/docs/api/ffi.md
@@ -229,7 +229,11 @@ const lib = linkSymbols({
},
});
-const [major, minor, patch] = [lib.symbols.getMajor(), lib.symbols.getMinor(), lib.symbols.getPatch()];
+const [major, minor, patch] = [
+ lib.symbols.getMajor(),
+ lib.symbols.getMinor(),
+ lib.symbols.getPatch(),
+];
```
## Callbacks
@@ -249,10 +253,13 @@ const {
},
});
-const searchIterator = new JSCallback((ptr, length) => /hello/.test(new CString(ptr, length)), {
- returns: "bool",
- args: ["ptr", "usize"],
-});
+const searchIterator = new JSCallback(
+ (ptr, length) => /hello/.test(new CString(ptr, length)),
+ {
+ returns: "bool",
+ args: ["ptr", "usize"],
+ },
+);
const str = Buffer.from("wwutwutwutwutwutwutwutwutwutwutut\0", "utf8");
if (search(ptr(str), searchIterator)) {
@@ -376,10 +383,6 @@ If you want to track when a `TypedArray` is no longer in use from JavaScript, yo
#### From C, Rust, Zig, etc
-{% callout %}
-**Note** — Available in Bun v0.1.8 and later.
-{% /callout %}
-
If you want to track when a `TypedArray` is no longer in use from C or FFI, you can pass a callback and an optional context pointer to `toArrayBuffer` or `toBuffer`. This function is called at some point later, once the garbage collector frees the underlying `ArrayBuffer` JavaScript object.
The expected signature is the same as in [JavaScriptCore's C API](https://developer.apple.com/documentation/javascriptcore/jstypedarraybytesdeallocator?language=objc):
diff --git a/docs/api/hashing.md b/docs/api/hashing.md
index 13a285693..0a32b567d 100644
--- a/docs/api/hashing.md
+++ b/docs/api/hashing.md
@@ -6,10 +6,6 @@ Bun implements the `createHash` and `createHmac` functions from [`node:crypto`](
## `Bun.password`
-{% callout %}
-**Note** — Added in Bun 0.6.8.
-{% /callout %}
-
`Bun.password` is a collection of utility functions for hashing and verifying passwords with various cryptographically secure algorithms.
```ts
diff --git a/docs/api/http.md b/docs/api/http.md
index ec32274d7..770b46478 100644
--- a/docs/api/http.md
+++ b/docs/api/http.md
@@ -140,12 +140,6 @@ Bun.serve({
});
```
-{% callout %}
-
-**Note** — Earlier versions of Bun supported passing a file path as `keyFile` and `certFile`; this has been deprecated as of `v0.6.3`.
-
-{% /callout %}
-
If your private key is encrypted with a passphrase, provide a value for `passphrase` to decrypt it.
```ts-diff
@@ -231,7 +225,7 @@ serve({
⚡️ **Speed** — Bun automatically uses the [`sendfile(2)`](https://man7.org/linux/man-pages/man2/sendfile.2.html) system call when possible, enabling zero-copy file transfers in the kernel—the fastest way to send files.
{% /callout %}
-**[v0.3.0+]** You can send part of a file using the [`slice(start, end)`](https://developer.mozilla.org/en-US/docs/Web/API/Blob/slice) method on the `Bun.file` object. This automatically sets the `Content-Range` and `Content-Length` headers on the `Response` object.
+You can send part of a file using the [`slice(start, end)`](https://developer.mozilla.org/en-US/docs/Web/API/Blob/slice) method on the `Bun.file` object. This automatically sets the `Content-Range` and `Content-Length` headers on the `Response` object.
```ts
Bun.serve({
diff --git a/docs/api/spawn.md b/docs/api/spawn.md
index b040272b5..a85f9d08c 100644
--- a/docs/api/spawn.md
+++ b/docs/api/spawn.md
@@ -28,7 +28,9 @@ By default, the input stream of the subprocess is undefined; it can be configure
```ts
const proc = Bun.spawn(["cat"], {
- stdin: await fetch("https://raw.githubusercontent.com/oven-sh/bun/main/examples/hashing.js"),
+ stdin: await fetch(
+ "https://raw.githubusercontent.com/oven-sh/bun/main/examples/hashing.js",
+ ),
});
const text = await new Response(proc.stdout).text();
@@ -209,7 +211,7 @@ Bun's `spawnSync` spawns processes 60% faster than the Node.js `child_process` m
```bash
$ bun spawn.mjs
cpu: Apple M1 Max
-runtime: bun 0.2.0 (arm64-darwin)
+runtime: bun 1.x (arm64-darwin)
benchmark time (avg) (min … max) p75 p99 p995
--------------------------------------------------------- -----------------------------
@@ -230,10 +232,15 @@ A simple reference of the Spawn API and types are shown below. The real types ha
```ts
interface Bun {
spawn(command: string[], options?: SpawnOptions.OptionsObject): Subprocess;
- spawnSync(command: string[], options?: SpawnOptions.OptionsObject): SyncSubprocess;
+ spawnSync(
+ command: string[],
+ options?: SpawnOptions.OptionsObject,
+ ): SyncSubprocess;
spawn(options: { cmd: string[] } & SpawnOptions.OptionsObject): Subprocess;
- spawnSync(options: { cmd: string[] } & SpawnOptions.OptionsObject): SyncSubprocess;
+ spawnSync(
+ options: { cmd: string[] } & SpawnOptions.OptionsObject,
+ ): SyncSubprocess;
}
namespace SpawnOptions {
@@ -243,7 +250,12 @@ namespace SpawnOptions {
stdin?: SpawnOptions.Readable;
stdout?: SpawnOptions.Writable;
stderr?: SpawnOptions.Writable;
- onExit?: (proc: Subprocess, exitCode: number | null, signalCode: string | null, error: Error | null) => void;
+ onExit?: (
+ proc: Subprocess,
+ exitCode: number | null,
+ signalCode: string | null,
+ error: Error | null,
+ ) => void;
}
type Readable =
diff --git a/docs/api/tcp.md b/docs/api/tcp.md
index c9190875a..cba440f01 100644
--- a/docs/api/tcp.md
+++ b/docs/api/tcp.md
@@ -76,12 +76,6 @@ Bun.listen({
});
```
-{% callout %}
-
-**Note** — Earlier versions of Bun supported passing a file path as `keyFile` and `certFile`; this has been deprecated as of `v0.6.3`.
-
-{% /callout %}
-
The `key` and `cert` fields expect the _contents_ of your TLS key and certificate. This can be a string, `BunFile`, `TypedArray`, or `Buffer`.
```ts
@@ -95,7 +89,7 @@ Bun.listen({
// string
key: fs.readFileSync("./key.pem", "utf8"),
// array of above
- key: [Bun.file('./key1.pem'), Bun.file('./key2.pem')]
+ key: [Bun.file("./key1.pem"), Bun.file("./key2.pem")],
},
});
```
diff --git a/docs/api/utils.md b/docs/api/utils.md
index 8b166e3e8..de2dc6994 100644
--- a/docs/api/utils.md
+++ b/docs/api/utils.md
@@ -43,7 +43,7 @@ This is analogous to the [`require.main = module` trick](https://stackoverflow.c
## `Bun.sleep()`
-`Bun.sleep(ms: number)` (added in Bun v0.5.6)
+`Bun.sleep(ms: number)`
Returns a `Promise` that resolves after the given number of milliseconds.
@@ -65,7 +65,7 @@ console.log("hello one second later!");
## `Bun.sleepSync()`
-`Bun.sleepSync(ms: number)` (added in Bun v0.5.6)
+`Bun.sleepSync(ms: number)`
A blocking synchronous version of `Bun.sleep`.
@@ -108,7 +108,7 @@ console.log(ls); // null
## `Bun.peek()`
-`Bun.peek(prom: Promise)` (added in Bun v0.2.2)
+`Bun.peek(prom: Promise)`
Reads a promise's result without `await` or `.then`, but only if the promise has already fulfilled or rejected.
diff --git a/docs/api/websockets.md b/docs/api/websockets.md
index b8b7f7a8e..defc9e18c 100644
--- a/docs/api/websockets.md
+++ b/docs/api/websockets.md
@@ -12,6 +12,18 @@
Internally Bun's WebSocket implementation is built on [uWebSockets](https://github.com/uNetworking/uWebSockets).
{% /callout %}
+## Connect to a WebSocket server
+
+{% callout %}
+**🚧** — The `WebSocket` client still does not pass the full [Autobahn test suite](https://github.com/crossbario/autobahn-testsuite) and should not be considered ready for production.
+{% /callout %}
+
+Bun implements the `WebSocket` class. To create a WebSocket client that connects to a `ws://` or `wss://` server, create an instance of `WebSocket`, as you would in the browser.
+
+```ts
+const socket = new WebSocket("ws://localhost:3000");
+```
+
## Start a WebSocket server
Below is a simple WebSocket server built with `Bun.serve`, in which all incoming requests are [upgraded](https://developer.mozilla.org/en-US/docs/Web/HTTP/Protocol_upgrade_mechanism) to WebSocket connections in the `fetch` handler. The socket handlers are declared in the `websocket` parameter.
diff --git a/docs/api/workers.md b/docs/api/workers.md
index cdf6b76c5..417b77148 100644
--- a/docs/api/workers.md
+++ b/docs/api/workers.md
@@ -1,5 +1,5 @@
{% callout %}
-`Worker` support was added in Bun v0.7.0.
+**🚧** — The `Worker` API is still experimental and should not be considered ready for production.
{% /callout %}
[`Worker`](https://developer.mozilla.org/en-US/docs/Web/API/Worker) lets you start and communicate with a new JavaScript instance running on a separate thread while sharing I/O resources with the main thread.