bun-types 1.3.2-canary.20251104T140728 → 1.3.2-canary.20251106T140813
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bun.d.ts +4 -4
- package/docs/README.md +28 -0
- package/globals.d.ts +0 -1
- package/overrides.d.ts +45 -15
- package/package.json +1 -1
- package/test.d.ts +1 -1
- package/docs/api/binary-data.md +0 -1038
- package/docs/api/cc.md +0 -197
- package/docs/api/color.md +0 -262
- package/docs/api/console.md +0 -57
- package/docs/api/cookie.md +0 -449
- package/docs/api/dns.md +0 -110
- package/docs/api/fetch.md +0 -463
- package/docs/api/ffi.md +0 -557
- package/docs/api/file-io.md +0 -366
- package/docs/api/file-system-router.md +0 -112
- package/docs/api/file.md +0 -19
- package/docs/api/glob.md +0 -178
- package/docs/api/globals.md +0 -387
- package/docs/api/hashing.md +0 -319
- package/docs/api/html-rewriter.md +0 -334
- package/docs/api/http.md +0 -1408
- package/docs/api/import-meta.md +0 -69
- package/docs/api/node-api.md +0 -14
- package/docs/api/redis.md +0 -597
- package/docs/api/s3.md +0 -850
- package/docs/api/secrets.md +0 -319
- package/docs/api/semver.md +0 -52
- package/docs/api/spawn.md +0 -582
- package/docs/api/sql.md +0 -1374
- package/docs/api/sqlite.md +0 -694
- package/docs/api/streams.md +0 -230
- package/docs/api/tcp.md +0 -221
- package/docs/api/transpiler.md +0 -276
- package/docs/api/udp.md +0 -123
- package/docs/api/utils.md +0 -891
- package/docs/api/websockets.md +0 -573
- package/docs/api/workers.md +0 -322
- package/docs/api/yaml.md +0 -668
- package/docs/benchmarks.md +0 -120
- package/docs/bun-flavored-toml.md +0 -42
- package/docs/bundler/css.md +0 -1028
- package/docs/bundler/css_modules.md +0 -145
- package/docs/bundler/executables.md +0 -626
- package/docs/bundler/fullstack.md +0 -418
- package/docs/bundler/hmr.md +0 -234
- package/docs/bundler/html.md +0 -349
- package/docs/bundler/index.md +0 -1735
- package/docs/bundler/intro.md +0 -75
- package/docs/bundler/loaders.md +0 -410
- package/docs/bundler/macros.md +0 -329
- package/docs/bundler/plugins.md +0 -449
- package/docs/bundler/vs-esbuild.md +0 -1127
- package/docs/cli/add.md +0 -173
- package/docs/cli/bun-completions.md +0 -3
- package/docs/cli/bun-create.md +0 -338
- package/docs/cli/bun-install.md +0 -349
- package/docs/cli/bun-upgrade.md +0 -39
- package/docs/cli/bunx.md +0 -89
- package/docs/cli/filter.md +0 -90
- package/docs/cli/info.md +0 -65
- package/docs/cli/init.md +0 -85
- package/docs/cli/install.md +0 -344
- package/docs/cli/link.md +0 -40
- package/docs/cli/outdated.md +0 -90
- package/docs/cli/patch-commit.md +0 -11
- package/docs/cli/pm.md +0 -285
- package/docs/cli/publish.md +0 -120
- package/docs/cli/remove.md +0 -7
- package/docs/cli/run.md +0 -261
- package/docs/cli/test.md +0 -397
- package/docs/cli/unlink.md +0 -9
- package/docs/cli/update.md +0 -129
- package/docs/cli/why.md +0 -67
- package/docs/contributing/upgrading-webkit.md +0 -57
- package/docs/ecosystem/elysia.md +0 -24
- package/docs/ecosystem/express.md +0 -37
- package/docs/ecosystem/hono.md +0 -18
- package/docs/ecosystem/react.md +0 -65
- package/docs/ecosystem/stric.md +0 -38
- package/docs/guides/binary/arraybuffer-to-array.md +0 -27
- package/docs/guides/binary/arraybuffer-to-blob.md +0 -24
- package/docs/guides/binary/arraybuffer-to-buffer.md +0 -25
- package/docs/guides/binary/arraybuffer-to-string.md +0 -15
- package/docs/guides/binary/arraybuffer-to-typedarray.md +0 -39
- package/docs/guides/binary/blob-to-arraybuffer.md +0 -14
- package/docs/guides/binary/blob-to-dataview.md +0 -14
- package/docs/guides/binary/blob-to-stream.md +0 -14
- package/docs/guides/binary/blob-to-string.md +0 -15
- package/docs/guides/binary/blob-to-typedarray.md +0 -14
- package/docs/guides/binary/buffer-to-arraybuffer.md +0 -14
- package/docs/guides/binary/buffer-to-blob.md +0 -14
- package/docs/guides/binary/buffer-to-readablestream.md +0 -41
- package/docs/guides/binary/buffer-to-string.md +0 -25
- package/docs/guides/binary/buffer-to-typedarray.md +0 -14
- package/docs/guides/binary/dataview-to-string.md +0 -15
- package/docs/guides/binary/typedarray-to-arraybuffer.md +0 -25
- package/docs/guides/binary/typedarray-to-blob.md +0 -16
- package/docs/guides/binary/typedarray-to-buffer.md +0 -14
- package/docs/guides/binary/typedarray-to-dataview.md +0 -14
- package/docs/guides/binary/typedarray-to-readablestream.md +0 -41
- package/docs/guides/binary/typedarray-to-string.md +0 -16
- package/docs/guides/deployment/railway.md +0 -157
- package/docs/guides/ecosystem/astro.md +0 -72
- package/docs/guides/ecosystem/discordjs.md +0 -77
- package/docs/guides/ecosystem/docker.md +0 -140
- package/docs/guides/ecosystem/drizzle.md +0 -185
- package/docs/guides/ecosystem/edgedb.md +0 -228
- package/docs/guides/ecosystem/elysia.md +0 -31
- package/docs/guides/ecosystem/express.md +0 -40
- package/docs/guides/ecosystem/hono.md +0 -39
- package/docs/guides/ecosystem/mongoose.md +0 -87
- package/docs/guides/ecosystem/neon-drizzle.md +0 -220
- package/docs/guides/ecosystem/neon-serverless-postgres.md +0 -55
- package/docs/guides/ecosystem/nextjs.md +0 -49
- package/docs/guides/ecosystem/nuxt.md +0 -56
- package/docs/guides/ecosystem/pm2.md +0 -57
- package/docs/guides/ecosystem/prisma.md +0 -141
- package/docs/guides/ecosystem/qwik.md +0 -107
- package/docs/guides/ecosystem/react.md +0 -50
- package/docs/guides/ecosystem/remix.md +0 -78
- package/docs/guides/ecosystem/render.md +0 -79
- package/docs/guides/ecosystem/sentry.md +0 -52
- package/docs/guides/ecosystem/solidstart.md +0 -58
- package/docs/guides/ecosystem/ssr-react.md +0 -51
- package/docs/guides/ecosystem/stric.md +0 -55
- package/docs/guides/ecosystem/sveltekit.md +0 -125
- package/docs/guides/ecosystem/systemd.md +0 -113
- package/docs/guides/ecosystem/vite.md +0 -71
- package/docs/guides/html-rewriter/extract-links.md +0 -68
- package/docs/guides/html-rewriter/extract-social-meta.md +0 -93
- package/docs/guides/http/cluster.md +0 -66
- package/docs/guides/http/fetch-unix.md +0 -33
- package/docs/guides/http/fetch.md +0 -24
- package/docs/guides/http/file-uploads.md +0 -94
- package/docs/guides/http/hot.md +0 -26
- package/docs/guides/http/proxy.md +0 -24
- package/docs/guides/http/server.md +0 -46
- package/docs/guides/http/simple.md +0 -18
- package/docs/guides/http/stream-file.md +0 -48
- package/docs/guides/http/stream-iterator.md +0 -47
- package/docs/guides/http/stream-node-streams-in-bun.md +0 -20
- package/docs/guides/http/tls.md +0 -30
- package/docs/guides/install/add-dev.md +0 -26
- package/docs/guides/install/add-git.md +0 -36
- package/docs/guides/install/add-optional.md +0 -25
- package/docs/guides/install/add-peer.md +0 -43
- package/docs/guides/install/add-tarball.md +0 -33
- package/docs/guides/install/add.md +0 -42
- package/docs/guides/install/azure-artifacts.md +0 -73
- package/docs/guides/install/cicd.md +0 -41
- package/docs/guides/install/custom-registry.md +0 -30
- package/docs/guides/install/from-npm-install-to-bun-install.md +0 -214
- package/docs/guides/install/git-diff-bun-lockfile.md +0 -44
- package/docs/guides/install/jfrog-artifactory.md +0 -28
- package/docs/guides/install/npm-alias.md +0 -23
- package/docs/guides/install/registry-scope.md +0 -38
- package/docs/guides/install/trusted.md +0 -46
- package/docs/guides/install/workspaces.md +0 -70
- package/docs/guides/install/yarnlock.md +0 -44
- package/docs/guides/process/argv.md +0 -58
- package/docs/guides/process/ctrl-c.md +0 -16
- package/docs/guides/process/ipc.md +0 -66
- package/docs/guides/process/nanoseconds.md +0 -13
- package/docs/guides/process/os-signals.md +0 -39
- package/docs/guides/process/spawn-stderr.md +0 -31
- package/docs/guides/process/spawn-stdout.md +0 -26
- package/docs/guides/process/spawn.md +0 -41
- package/docs/guides/process/stdin.md +0 -54
- package/docs/guides/read-file/arraybuffer.md +0 -28
- package/docs/guides/read-file/buffer.md +0 -19
- package/docs/guides/read-file/exists.md +0 -16
- package/docs/guides/read-file/json.md +0 -17
- package/docs/guides/read-file/mime.md +0 -20
- package/docs/guides/read-file/stream.md +0 -26
- package/docs/guides/read-file/string.md +0 -22
- package/docs/guides/read-file/uint8array.md +0 -21
- package/docs/guides/read-file/watch.md +0 -68
- package/docs/guides/runtime/build-time-constants.md +0 -293
- package/docs/guides/runtime/cicd.md +0 -43
- package/docs/guides/runtime/codesign-macos-executable.md +0 -56
- package/docs/guides/runtime/define-constant.md +0 -145
- package/docs/guides/runtime/delete-directory.md +0 -37
- package/docs/guides/runtime/delete-file.md +0 -19
- package/docs/guides/runtime/heap-snapshot.md +0 -26
- package/docs/guides/runtime/import-html.md +0 -15
- package/docs/guides/runtime/import-json.md +0 -44
- package/docs/guides/runtime/import-toml.md +0 -30
- package/docs/guides/runtime/import-yaml.md +0 -102
- package/docs/guides/runtime/read-env.md +0 -32
- package/docs/guides/runtime/set-env.md +0 -47
- package/docs/guides/runtime/shell.md +0 -40
- package/docs/guides/runtime/timezone.md +0 -35
- package/docs/guides/runtime/tsconfig-paths.md +0 -29
- package/docs/guides/runtime/typescript.md +0 -49
- package/docs/guides/runtime/vscode-debugger.md +0 -47
- package/docs/guides/runtime/web-debugger.md +0 -82
- package/docs/guides/streams/node-readable-to-arraybuffer.md +0 -11
- package/docs/guides/streams/node-readable-to-blob.md +0 -11
- package/docs/guides/streams/node-readable-to-json.md +0 -12
- package/docs/guides/streams/node-readable-to-string.md +0 -12
- package/docs/guides/streams/node-readable-to-uint8array.md +0 -11
- package/docs/guides/streams/to-array.md +0 -14
- package/docs/guides/streams/to-arraybuffer.md +0 -14
- package/docs/guides/streams/to-blob.md +0 -14
- package/docs/guides/streams/to-buffer.md +0 -15
- package/docs/guides/streams/to-json.md +0 -14
- package/docs/guides/streams/to-string.md +0 -14
- package/docs/guides/streams/to-typedarray.md +0 -22
- package/docs/guides/test/bail.md +0 -22
- package/docs/guides/test/coverage-threshold.md +0 -60
- package/docs/guides/test/coverage.md +0 -44
- package/docs/guides/test/happy-dom.md +0 -68
- package/docs/guides/test/migrate-from-jest.md +0 -143
- package/docs/guides/test/mock-clock.md +0 -48
- package/docs/guides/test/mock-functions.md +0 -68
- package/docs/guides/test/rerun-each.md +0 -14
- package/docs/guides/test/run-tests.md +0 -111
- package/docs/guides/test/skip-tests.md +0 -39
- package/docs/guides/test/snapshot.md +0 -95
- package/docs/guides/test/spy-on.md +0 -46
- package/docs/guides/test/svelte-test.md +0 -120
- package/docs/guides/test/testing-library.md +0 -92
- package/docs/guides/test/timeout.md +0 -15
- package/docs/guides/test/todo-tests.md +0 -67
- package/docs/guides/test/update-snapshots.md +0 -46
- package/docs/guides/test/watch-mode.md +0 -19
- package/docs/guides/util/base64.md +0 -15
- package/docs/guides/util/deep-equals.md +0 -39
- package/docs/guides/util/deflate.md +0 -18
- package/docs/guides/util/detect-bun.md +0 -23
- package/docs/guides/util/entrypoint.md +0 -17
- package/docs/guides/util/escape-html.md +0 -22
- package/docs/guides/util/file-url-to-path.md +0 -14
- package/docs/guides/util/gzip.md +0 -18
- package/docs/guides/util/hash-a-password.md +0 -54
- package/docs/guides/util/import-meta-dir.md +0 -13
- package/docs/guides/util/import-meta-file.md +0 -13
- package/docs/guides/util/import-meta-path.md +0 -13
- package/docs/guides/util/javascript-uuid.md +0 -23
- package/docs/guides/util/main.md +0 -32
- package/docs/guides/util/path-to-file-url.md +0 -14
- package/docs/guides/util/sleep.md +0 -22
- package/docs/guides/util/version.md +0 -21
- package/docs/guides/util/which-path-to-executable-bin.md +0 -15
- package/docs/guides/websocket/compression.md +0 -31
- package/docs/guides/websocket/context.md +0 -77
- package/docs/guides/websocket/pubsub.md +0 -41
- package/docs/guides/websocket/simple.md +0 -33
- package/docs/guides/write-file/append.md +0 -52
- package/docs/guides/write-file/basic.md +0 -44
- package/docs/guides/write-file/blob.md +0 -28
- package/docs/guides/write-file/cat.md +0 -17
- package/docs/guides/write-file/file-cp.md +0 -16
- package/docs/guides/write-file/filesink.md +0 -52
- package/docs/guides/write-file/response.md +0 -17
- package/docs/guides/write-file/stdout.md +0 -21
- package/docs/guides/write-file/stream.md +0 -17
- package/docs/guides/write-file/unlink.md +0 -16
- package/docs/index.md +0 -77
- package/docs/install/audit.md +0 -57
- package/docs/install/cache.md +0 -59
- package/docs/install/catalogs.md +0 -298
- package/docs/install/index.md +0 -248
- package/docs/install/isolated.md +0 -197
- package/docs/install/lifecycle.md +0 -46
- package/docs/install/lockfile.md +0 -58
- package/docs/install/npmrc.md +0 -105
- package/docs/install/overrides.md +0 -73
- package/docs/install/patch.md +0 -59
- package/docs/install/registries.md +0 -30
- package/docs/install/security-scanner-api.md +0 -81
- package/docs/install/workspaces.md +0 -114
- package/docs/installation.md +0 -327
- package/docs/project/asan.md +0 -124
- package/docs/project/benchmarking.md +0 -203
- package/docs/project/bindgen.md +0 -225
- package/docs/project/building-windows.md +0 -162
- package/docs/project/contributing.md +0 -347
- package/docs/project/internals/build-process-for-ci.md +0 -75
- package/docs/project/licensing.md +0 -73
- package/docs/project/roadmap.md +0 -87
- package/docs/quickstart.md +0 -157
- package/docs/runtime/autoimport.md +0 -94
- package/docs/runtime/bun-apis.md +0 -207
- package/docs/runtime/bunfig.md +0 -772
- package/docs/runtime/debugger.md +0 -325
- package/docs/runtime/env.md +0 -253
- package/docs/runtime/hot.md +0 -145
- package/docs/runtime/index.md +0 -312
- package/docs/runtime/jsx.md +0 -385
- package/docs/runtime/loaders.md +0 -130
- package/docs/runtime/modules.md +0 -320
- package/docs/runtime/nodejs-apis.md +0 -463
- package/docs/runtime/plugins.md +0 -561
- package/docs/runtime/shell.md +0 -605
- package/docs/runtime/typescript.md +0 -139
- package/docs/runtime/web-apis.md +0 -128
- package/docs/test/configuration.md +0 -154
- package/docs/test/coverage.md +0 -142
- package/docs/test/discovery.md +0 -85
- package/docs/test/dom.md +0 -75
- package/docs/test/examples/concurrent-test-glob.md +0 -132
- package/docs/test/hot.md +0 -15
- package/docs/test/lifecycle.md +0 -81
- package/docs/test/mocks.md +0 -313
- package/docs/test/reporters.md +0 -117
- package/docs/test/runtime-behavior.md +0 -95
- package/docs/test/snapshots.md +0 -68
- package/docs/test/time.md +0 -126
- package/docs/test/writing.md +0 -825
- package/docs/typescript.md +0 -53
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: Import a TOML file
|
|
3
|
-
---
|
|
4
|
-
|
|
5
|
-
Bun natively supports importing `.toml` files.
|
|
6
|
-
|
|
7
|
-
```toml#data.toml
|
|
8
|
-
name = "bun"
|
|
9
|
-
version = "1.0.0"
|
|
10
|
-
|
|
11
|
-
[author]
|
|
12
|
-
name = "John Dough"
|
|
13
|
-
email = "john@dough.com"
|
|
14
|
-
```
|
|
15
|
-
|
|
16
|
-
---
|
|
17
|
-
|
|
18
|
-
Import the file like any other source file.
|
|
19
|
-
|
|
20
|
-
```ts
|
|
21
|
-
import data from "./data.toml";
|
|
22
|
-
|
|
23
|
-
data.name; // => "bun"
|
|
24
|
-
data.version; // => "1.0.0"
|
|
25
|
-
data.author.name; // => "John Dough"
|
|
26
|
-
```
|
|
27
|
-
|
|
28
|
-
---
|
|
29
|
-
|
|
30
|
-
See [Docs > Runtime > TypeScript](https://bun.com/docs/runtime/typescript) for more information on using TypeScript with Bun.
|
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: Import a YAML file
|
|
3
|
-
---
|
|
4
|
-
|
|
5
|
-
Bun natively supports `.yaml` and `.yml` imports.
|
|
6
|
-
|
|
7
|
-
```yaml#config.yaml
|
|
8
|
-
database:
|
|
9
|
-
host: localhost
|
|
10
|
-
port: 5432
|
|
11
|
-
name: myapp
|
|
12
|
-
|
|
13
|
-
server:
|
|
14
|
-
port: 3000
|
|
15
|
-
timeout: 30
|
|
16
|
-
|
|
17
|
-
features:
|
|
18
|
-
auth: true
|
|
19
|
-
rateLimit: true
|
|
20
|
-
```
|
|
21
|
-
|
|
22
|
-
---
|
|
23
|
-
|
|
24
|
-
Import the file like any other source file.
|
|
25
|
-
|
|
26
|
-
```ts
|
|
27
|
-
import config from "./config.yaml";
|
|
28
|
-
|
|
29
|
-
config.database.host; // => "localhost"
|
|
30
|
-
config.server.port; // => 3000
|
|
31
|
-
config.features.auth; // => true
|
|
32
|
-
```
|
|
33
|
-
|
|
34
|
-
---
|
|
35
|
-
|
|
36
|
-
You can also use named imports to destructure top-level properties:
|
|
37
|
-
|
|
38
|
-
```ts
|
|
39
|
-
import { database, server, features } from "./config.yaml";
|
|
40
|
-
|
|
41
|
-
console.log(database.name); // => "myapp"
|
|
42
|
-
console.log(server.timeout); // => 30
|
|
43
|
-
console.log(features.rateLimit); // => true
|
|
44
|
-
```
|
|
45
|
-
|
|
46
|
-
---
|
|
47
|
-
|
|
48
|
-
Bun also supports [Import Attributes](https://github.com/tc39/proposal-import-attributes) syntax:
|
|
49
|
-
|
|
50
|
-
```ts
|
|
51
|
-
import config from "./config.yaml" with { type: "yaml" };
|
|
52
|
-
|
|
53
|
-
config.database.port; // => 5432
|
|
54
|
-
```
|
|
55
|
-
|
|
56
|
-
---
|
|
57
|
-
|
|
58
|
-
For parsing YAML strings at runtime, use `Bun.YAML.parse()`:
|
|
59
|
-
|
|
60
|
-
```ts
|
|
61
|
-
const yamlString = `
|
|
62
|
-
name: John Doe
|
|
63
|
-
age: 30
|
|
64
|
-
hobbies:
|
|
65
|
-
- reading
|
|
66
|
-
- coding
|
|
67
|
-
`;
|
|
68
|
-
|
|
69
|
-
const data = Bun.YAML.parse(yamlString);
|
|
70
|
-
console.log(data.name); // => "John Doe"
|
|
71
|
-
console.log(data.hobbies); // => ["reading", "coding"]
|
|
72
|
-
```
|
|
73
|
-
|
|
74
|
-
---
|
|
75
|
-
|
|
76
|
-
## TypeScript Support
|
|
77
|
-
|
|
78
|
-
To add TypeScript support for your YAML imports, create a declaration file with `.d.ts` appended to the YAML filename (e.g., `config.yaml` → `config.yaml.d.ts`);
|
|
79
|
-
|
|
80
|
-
```ts#config.yaml.d.ts
|
|
81
|
-
const contents: {
|
|
82
|
-
database: {
|
|
83
|
-
host: string;
|
|
84
|
-
port: number;
|
|
85
|
-
name: string;
|
|
86
|
-
};
|
|
87
|
-
server: {
|
|
88
|
-
port: number;
|
|
89
|
-
timeout: number;
|
|
90
|
-
};
|
|
91
|
-
features: {
|
|
92
|
-
auth: boolean;
|
|
93
|
-
rateLimit: boolean;
|
|
94
|
-
};
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
export = contents;
|
|
98
|
-
```
|
|
99
|
-
|
|
100
|
-
---
|
|
101
|
-
|
|
102
|
-
See [Docs > API > YAML](https://bun.com/docs/api/yaml) for complete documentation on YAML support in Bun.
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: Read environment variables
|
|
3
|
-
---
|
|
4
|
-
|
|
5
|
-
The current environment variables can be accessed via `process.env`.
|
|
6
|
-
|
|
7
|
-
```ts
|
|
8
|
-
process.env.API_TOKEN; // => "secret"
|
|
9
|
-
```
|
|
10
|
-
|
|
11
|
-
---
|
|
12
|
-
|
|
13
|
-
Bun also exposes these variables via `Bun.env`, which is a simple alias of `process.env`.
|
|
14
|
-
|
|
15
|
-
```ts
|
|
16
|
-
Bun.env.API_TOKEN; // => "secret"
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
-
---
|
|
20
|
-
|
|
21
|
-
To print all currently-set environment variables to the command line, run `bun --print process.env`. This is useful for debugging.
|
|
22
|
-
|
|
23
|
-
```sh
|
|
24
|
-
$ bun --print process.env
|
|
25
|
-
BAZ=stuff
|
|
26
|
-
FOOBAR=aaaaaa
|
|
27
|
-
<lots more lines>
|
|
28
|
-
```
|
|
29
|
-
|
|
30
|
-
---
|
|
31
|
-
|
|
32
|
-
See [Docs > Runtime > Environment variables](https://bun.com/docs/runtime/env) for more information on using environment variables with Bun.
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: Set environment variables
|
|
3
|
-
---
|
|
4
|
-
|
|
5
|
-
The current environment variables can be accessed via `process.env` or `Bun.env`.
|
|
6
|
-
|
|
7
|
-
```ts
|
|
8
|
-
Bun.env.API_TOKEN; // => "secret"
|
|
9
|
-
process.env.API_TOKEN; // => "secret"
|
|
10
|
-
```
|
|
11
|
-
|
|
12
|
-
---
|
|
13
|
-
|
|
14
|
-
Set these variables in a `.env` file.
|
|
15
|
-
|
|
16
|
-
Bun reads the following files automatically (listed in order of increasing precedence).
|
|
17
|
-
|
|
18
|
-
- `.env`
|
|
19
|
-
- `.env.production`, `.env.development`, `.env.test` (depending on value of `NODE_ENV`)
|
|
20
|
-
- `.env.local` (not loaded when `NODE_ENV=test`)
|
|
21
|
-
|
|
22
|
-
```txt#.env
|
|
23
|
-
FOO=hello
|
|
24
|
-
BAR=world
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
---
|
|
28
|
-
|
|
29
|
-
Variables can also be set via the command line.
|
|
30
|
-
|
|
31
|
-
{% codetabs %}
|
|
32
|
-
|
|
33
|
-
```sh#Linux/macOS
|
|
34
|
-
$ FOO=helloworld bun run dev
|
|
35
|
-
```
|
|
36
|
-
|
|
37
|
-
```sh#Windows
|
|
38
|
-
# Using CMD
|
|
39
|
-
$ set FOO=helloworld && bun run dev
|
|
40
|
-
|
|
41
|
-
# Using PowerShell
|
|
42
|
-
$ $env:FOO="helloworld"; bun run dev
|
|
43
|
-
```
|
|
44
|
-
|
|
45
|
-
## {% /codetabs %}
|
|
46
|
-
|
|
47
|
-
See [Docs > Runtime > Environment variables](https://bun.com/docs/runtime/env) for more information on using environment variables with Bun.
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: Run a Shell Command
|
|
3
|
-
---
|
|
4
|
-
|
|
5
|
-
Bun Shell is a cross-platform bash-like shell built in to Bun.
|
|
6
|
-
|
|
7
|
-
It provides a simple way to run shell commands in JavaScript and TypeScript. To get started, import the `$` function from the `bun` package and use it to run shell commands.
|
|
8
|
-
|
|
9
|
-
```ts#foo.ts
|
|
10
|
-
import { $ } from "bun";
|
|
11
|
-
|
|
12
|
-
await $`echo Hello, world!`; // => "Hello, world!"
|
|
13
|
-
```
|
|
14
|
-
|
|
15
|
-
---
|
|
16
|
-
|
|
17
|
-
The `$` function is a tagged template literal that runs the command and returns a promise that resolves with the command's output.
|
|
18
|
-
|
|
19
|
-
```ts#foo.ts
|
|
20
|
-
import { $ } from "bun";
|
|
21
|
-
|
|
22
|
-
const output = await $`ls -l`.text();
|
|
23
|
-
console.log(output);
|
|
24
|
-
```
|
|
25
|
-
|
|
26
|
-
---
|
|
27
|
-
|
|
28
|
-
To get each line of the output as an array, use the `lines` method.
|
|
29
|
-
|
|
30
|
-
```ts#foo.ts
|
|
31
|
-
import { $ } from "bun";
|
|
32
|
-
|
|
33
|
-
for await (const line of $`ls -l`.lines()) {
|
|
34
|
-
console.log(line);
|
|
35
|
-
}
|
|
36
|
-
```
|
|
37
|
-
|
|
38
|
-
---
|
|
39
|
-
|
|
40
|
-
See [Docs > API > Shell](https://bun.com/docs/runtime/shell) for complete documentation.
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: Set a time zone in Bun
|
|
3
|
-
---
|
|
4
|
-
|
|
5
|
-
Bun supports programmatically setting a default time zone for the lifetime of the `bun` process. To do set, set the value of the `TZ` environment variable to a [valid timezone identifier](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones).
|
|
6
|
-
|
|
7
|
-
{% callout %}
|
|
8
|
-
When running a file with `bun`, the timezone defaults to your system's configured local time zone.
|
|
9
|
-
|
|
10
|
-
When running tests with `bun test`, the timezone is set to `UTC` to make tests more deterministic.
|
|
11
|
-
{% /callout %}
|
|
12
|
-
|
|
13
|
-
```ts
|
|
14
|
-
process.env.TZ = "America/New_York";
|
|
15
|
-
```
|
|
16
|
-
|
|
17
|
-
---
|
|
18
|
-
|
|
19
|
-
Alternatively, this can be set from the command line when running a Bun command.
|
|
20
|
-
|
|
21
|
-
```sh
|
|
22
|
-
$ TZ=America/New_York bun run dev
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
---
|
|
26
|
-
|
|
27
|
-
Once `TZ` is set, any `Date` instances will have that time zone. By default all dates use your system's configured time zone.
|
|
28
|
-
|
|
29
|
-
```ts
|
|
30
|
-
new Date().getHours(); // => 18
|
|
31
|
-
|
|
32
|
-
process.env.TZ = "America/New_York";
|
|
33
|
-
|
|
34
|
-
new Date().getHours(); // => 21
|
|
35
|
-
```
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: Re-map import paths
|
|
3
|
-
---
|
|
4
|
-
|
|
5
|
-
Bun reads the `paths` field in your `tsconfig.json` to re-write import paths. This is useful for aliasing package names or avoiding long relative paths.
|
|
6
|
-
|
|
7
|
-
```json
|
|
8
|
-
{
|
|
9
|
-
"compilerOptions": {
|
|
10
|
-
"paths": {
|
|
11
|
-
"my-custom-name": ["zod"],
|
|
12
|
-
"@components/*": ["./src/components/*"]
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
```
|
|
17
|
-
|
|
18
|
-
---
|
|
19
|
-
|
|
20
|
-
With the above `tsconfig.json`, the following imports will be re-written:
|
|
21
|
-
|
|
22
|
-
```ts
|
|
23
|
-
import { z } from "my-custom-name"; // imports from "zod"
|
|
24
|
-
import { Button } from "@components/Button"; // imports from "./src/components/Button"
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
---
|
|
28
|
-
|
|
29
|
-
See [Docs > Runtime > TypeScript](https://bun.com/docs/runtime/typescript) for more information on using TypeScript with Bun.
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: Install TypeScript declarations for Bun
|
|
3
|
-
---
|
|
4
|
-
|
|
5
|
-
To install TypeScript definitions for Bun's built-in APIs in your project, install `@types/bun`.
|
|
6
|
-
|
|
7
|
-
```sh
|
|
8
|
-
$ bun add -d @types/bun # dev dependency
|
|
9
|
-
```
|
|
10
|
-
|
|
11
|
-
---
|
|
12
|
-
|
|
13
|
-
Below is the full set of recommended `compilerOptions` for a Bun project. With this `tsconfig.json`, you can use top-level await, extensioned or extensionless imports, and JSX.
|
|
14
|
-
|
|
15
|
-
```jsonc
|
|
16
|
-
{
|
|
17
|
-
"compilerOptions": {
|
|
18
|
-
// Environment setup & latest features
|
|
19
|
-
"lib": ["ESNext"],
|
|
20
|
-
"target": "ESNext",
|
|
21
|
-
"module": "Preserve",
|
|
22
|
-
"moduleDetection": "force",
|
|
23
|
-
"jsx": "react-jsx",
|
|
24
|
-
"allowJs": true,
|
|
25
|
-
|
|
26
|
-
// Bundler mode
|
|
27
|
-
"moduleResolution": "bundler",
|
|
28
|
-
"allowImportingTsExtensions": true,
|
|
29
|
-
"verbatimModuleSyntax": true,
|
|
30
|
-
"noEmit": true,
|
|
31
|
-
|
|
32
|
-
// Best practices
|
|
33
|
-
"strict": true,
|
|
34
|
-
"skipLibCheck": true,
|
|
35
|
-
"noFallthroughCasesInSwitch": true,
|
|
36
|
-
"noUncheckedIndexedAccess": true,
|
|
37
|
-
"noImplicitOverride": true,
|
|
38
|
-
|
|
39
|
-
// Some stricter flags (disabled by default)
|
|
40
|
-
"noUnusedLocals": false,
|
|
41
|
-
"noUnusedParameters": false,
|
|
42
|
-
"noPropertyAccessFromIndexSignature": false,
|
|
43
|
-
},
|
|
44
|
-
}
|
|
45
|
-
```
|
|
46
|
-
|
|
47
|
-
---
|
|
48
|
-
|
|
49
|
-
Refer to [Ecosystem > TypeScript](https://bun.com/docs/runtime/typescript) for a complete guide to TypeScript support in Bun.
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: Debugging Bun with the VS Code extension
|
|
3
|
-
---
|
|
4
|
-
|
|
5
|
-
{% note %}
|
|
6
|
-
|
|
7
|
-
VSCode extension support is currently buggy. We recommend the [Web Debugger](https://bun.com/guides/runtime/web-debugger) for now.
|
|
8
|
-
|
|
9
|
-
{% /note %}
|
|
10
|
-
|
|
11
|
-
Bun speaks the [WebKit Inspector Protocol](https://github.com/oven-sh/bun/blob/main/packages/bun-inspector-protocol/src/protocol/jsc/index.d.ts) so you can debug your code with an interactive debugger.
|
|
12
|
-
|
|
13
|
-
---
|
|
14
|
-
|
|
15
|
-
To install the extension, visit the [Bun for Visual Studio Code](https://marketplace.visualstudio.com/items?itemName=oven.bun-vscode) page on the VS Code marketplace website, then click Install.
|
|
16
|
-
|
|
17
|
-
{% image src="https://github.com/oven-sh/bun/assets/3084745/7c8c80e6-d49e-457a-a45e-45ebed946d56" /%}
|
|
18
|
-
|
|
19
|
-
---
|
|
20
|
-
|
|
21
|
-
Alternatively, search `bun-vscode` in the Extensions tab of VS Code.
|
|
22
|
-
|
|
23
|
-
{% image src="https://github.com/oven-sh/bun/assets/3084745/664b4c40-944c-4076-a4c2-f812aebd3dc9" /%}
|
|
24
|
-
|
|
25
|
-
---
|
|
26
|
-
|
|
27
|
-
Make sure you are installing the extension published by the verified Oven organization.
|
|
28
|
-
|
|
29
|
-
{% image src="https://github.com/oven-sh/bun/assets/3084745/73e6b09f-9ff1-4d85-b725-c5eb7215b6ae" /%}
|
|
30
|
-
|
|
31
|
-
---
|
|
32
|
-
|
|
33
|
-
Once installed, two new Bun-specific commands will appear in the Command Palette. To open the palette, click View > Command Palette, or type `Ctrl+Shift+P` (Windows, Linux) or `Cmd+Shift+P` on (Mac).
|
|
34
|
-
|
|
35
|
-
---
|
|
36
|
-
|
|
37
|
-
The `Bun: Run File` command will execute your code and print the output to the Debug Console in VS Code. Breakpoints will be ignored; this is similar to executing the file with `bun <file>` from the command line.
|
|
38
|
-
|
|
39
|
-
{% image src="https://github.com/oven-sh/bun/assets/3084745/1b2c7fd9-fbb9-486a-84d0-eb7ec135ded3" /%}
|
|
40
|
-
|
|
41
|
-
---
|
|
42
|
-
|
|
43
|
-
The `Bun: Debug File` command will execute your code and print the output to the Debug Console in VS Code. You can set breakpoints in your code by clicking to the left of a line number; a red dot should appear.
|
|
44
|
-
|
|
45
|
-
When you run the file with `Bun: Debug File`, execution will pause at the breakpoint. You can inspect the variables in scope and step through the code line-by-line using the VS Code controls.
|
|
46
|
-
|
|
47
|
-
{% image src="https://github.com/oven-sh/bun/assets/3084745/c579a36c-eb21-4a58-bc9c-74612aad82af" /%}
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: Debugging Bun with the web debugger
|
|
3
|
-
---
|
|
4
|
-
|
|
5
|
-
Bun speaks the [WebKit Inspector Protocol](https://github.com/oven-sh/bun/blob/main/packages/bun-vscode/types/jsc.d.ts). To enable debugging when running code with Bun, use the `--inspect` flag. For demonstration purposes, consider the following simple web server.
|
|
6
|
-
|
|
7
|
-
```ts#server.ts
|
|
8
|
-
Bun.serve({
|
|
9
|
-
fetch(req){
|
|
10
|
-
console.log(req.url);
|
|
11
|
-
return new Response("Hello, world!");
|
|
12
|
-
}
|
|
13
|
-
})
|
|
14
|
-
```
|
|
15
|
-
|
|
16
|
-
---
|
|
17
|
-
|
|
18
|
-
Let's run this file with the `--inspect` flag.
|
|
19
|
-
|
|
20
|
-
This automatically starts a WebSocket server on an available port that can be used to introspect the running Bun process. Various debugging tools can connect to this server to provide an interactive debugging experience.
|
|
21
|
-
|
|
22
|
-
Bun hosts a web-based debugger at [debug.bun.sh](https://debug.bun.sh). It is a modified version of WebKit's [Web Inspector Interface](https://webkit.org/web-inspector/web-inspector-interface/), which will look familiar to Safari users.
|
|
23
|
-
|
|
24
|
-
```sh
|
|
25
|
-
$ bun --inspect server.ts
|
|
26
|
-
------------------ Bun Inspector ------------------
|
|
27
|
-
Listening at:
|
|
28
|
-
ws://localhost:6499/0tqxs9exrgrm
|
|
29
|
-
|
|
30
|
-
Inspect in browser:
|
|
31
|
-
https://debug.bun.sh/#localhost:6499/0tqxs9exrgrm
|
|
32
|
-
------------------ Bun Inspector ------------------
|
|
33
|
-
```
|
|
34
|
-
|
|
35
|
-
---
|
|
36
|
-
|
|
37
|
-
Open the provided `debug.bun.sh` URL in your browser to start a debugging session. From this interface, you'll be able to view the source code of the running file, view and set breakpoints, and execute code with the built-in console.
|
|
38
|
-
|
|
39
|
-
{% image src="https://github.com/oven-sh/bun/assets/3084745/e6a976a8-80cc-4394-8925-539025cc025d" alt="Screenshot of Bun debugger, Console tab" /%}
|
|
40
|
-
|
|
41
|
-
---
|
|
42
|
-
|
|
43
|
-
Let's set a breakpoint. Navigate to the Sources tab; you should see the code from earlier. Click on the line number `3` to set a breakpoint on our `console.log(req.url)` statement.
|
|
44
|
-
|
|
45
|
-
{% image src="https://github.com/oven-sh/bun/assets/3084745/3b69c7e9-25ff-4f9d-acc4-caa736862935" alt="screenshot of Bun debugger" /%}
|
|
46
|
-
|
|
47
|
-
---
|
|
48
|
-
|
|
49
|
-
Then visit [`http://localhost:3000`](http://localhost:3000) in your web browser. This will send an HTTP request to our `localhost` web server. It will seem like the page isn't loading. Why? Because the program has paused execution at the breakpoint we set earlier.
|
|
50
|
-
|
|
51
|
-
Note how the UI has changed.
|
|
52
|
-
|
|
53
|
-
{% image src="https://github.com/oven-sh/bun/assets/3084745/8b565e58-5445-4061-9bc4-f41090dfe769" alt="screenshot of Bun debugger" /%}
|
|
54
|
-
|
|
55
|
-
---
|
|
56
|
-
|
|
57
|
-
At this point there's a lot we can do to introspect the current execution environment. We can use the console at the bottom to run arbitrary code in the context of the program, with full access to the variables in scope at our breakpoint.
|
|
58
|
-
|
|
59
|
-
{% image src="https://github.com/oven-sh/bun/assets/3084745/f4312b76-48ba-4a7d-b3b6-6205968ac681" /%}
|
|
60
|
-
|
|
61
|
-
---
|
|
62
|
-
|
|
63
|
-
On the right side of the Sources pane, we can see all local variables currently in scope, and drill down to see their properties and methods. Here, we're inspecting the `req` variable.
|
|
64
|
-
|
|
65
|
-
{% image src="https://github.com/oven-sh/bun/assets/3084745/63d7f843-5180-489c-aa94-87c486e68646" /%}
|
|
66
|
-
|
|
67
|
-
---
|
|
68
|
-
|
|
69
|
-
In the upper left of the Sources pane, we can control the execution of the program.
|
|
70
|
-
|
|
71
|
-
{% image src="https://github.com/oven-sh/bun/assets/3084745/41b76deb-7371-4461-9d5d-81b5a6d2f7a4" /%}
|
|
72
|
-
|
|
73
|
-
---
|
|
74
|
-
|
|
75
|
-
Here's a cheat sheet explaining the functions of the control flow buttons.
|
|
76
|
-
|
|
77
|
-
- _Continue script execution_ — continue running the program until the next breakpoint or exception.
|
|
78
|
-
- _Step over_ — The program will continue to the next line.
|
|
79
|
-
- _Step into_ — If the current statement contains a function call, the debugger will "step into" the called function.
|
|
80
|
-
- _Step out_ — If the current statement is a function call, the debugger will finish executing the call, then "step out" of the function to the location where it was called.
|
|
81
|
-
|
|
82
|
-
{% image src="https://github-production-user-asset-6210df.s3.amazonaws.com/3084745/261510346-6a94441c-75d3-413a-99a7-efa62365f83d.png" /%}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: Convert a Node.js Readable to an ArrayBuffer
|
|
3
|
-
---
|
|
4
|
-
|
|
5
|
-
To convert a Node.js `Readable` stream to an `ArrayBuffer` in Bun, you can create a new `Response` object with the stream as the body, then use `arrayBuffer()` to read the stream into an `ArrayBuffer`.
|
|
6
|
-
|
|
7
|
-
```ts
|
|
8
|
-
import { Readable } from "stream";
|
|
9
|
-
const stream = Readable.from(["Hello, ", "world!"]);
|
|
10
|
-
const buf = await new Response(stream).arrayBuffer();
|
|
11
|
-
```
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: Convert a Node.js Readable to a Blob
|
|
3
|
-
---
|
|
4
|
-
|
|
5
|
-
To convert a Node.js `Readable` stream to a [`Blob`](https://developer.mozilla.org/en-US/docs/Web/API/Blob) in Bun, you can create a new [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response) object with the stream as the body, then use [`response.blob()`](https://developer.mozilla.org/en-US/docs/Web/API/Response/blob) to read the stream into a [`Blob`](https://developer.mozilla.org/en-US/docs/Web/API/Blob).
|
|
6
|
-
|
|
7
|
-
```ts
|
|
8
|
-
import { Readable } from "stream";
|
|
9
|
-
const stream = Readable.from(["Hello, ", "world!"]);
|
|
10
|
-
const blob = await new Response(stream).blob();
|
|
11
|
-
```
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: Convert a Node.js Readable to JSON
|
|
3
|
-
---
|
|
4
|
-
|
|
5
|
-
To convert a Node.js `Readable` stream to a JSON object in Bun, you can create a new [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response) object with the stream as the body, then use [`response.json()`](https://developer.mozilla.org/en-US/docs/Web/API/Response/json) to read the stream into a JSON object.
|
|
6
|
-
|
|
7
|
-
```ts
|
|
8
|
-
import { Readable } from "stream";
|
|
9
|
-
const stream = Readable.from([JSON.stringify({ hello: "world" })]);
|
|
10
|
-
const json = await new Response(stream).json();
|
|
11
|
-
console.log(json); // { hello: "world" }
|
|
12
|
-
```
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: Convert a Node.js Readable to a string
|
|
3
|
-
---
|
|
4
|
-
|
|
5
|
-
To convert a Node.js `Readable` stream to a string in Bun, you can create a new [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response) object with the stream as the body, then use [`response.text()`](https://developer.mozilla.org/en-US/docs/Web/API/Response/text) to read the stream into a string.
|
|
6
|
-
|
|
7
|
-
```ts
|
|
8
|
-
import { Readable } from "stream";
|
|
9
|
-
const stream = Readable.from([Buffer.from("Hello, world!")]);
|
|
10
|
-
const text = await new Response(stream).text();
|
|
11
|
-
console.log(text); // "Hello, world!"
|
|
12
|
-
```
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: Convert a Node.js Readable to an Uint8Array
|
|
3
|
-
---
|
|
4
|
-
|
|
5
|
-
To convert a Node.js `Readable` stream to an `Uint8Array` in Bun, you can create a new `Response` object with the stream as the body, then use `bytes()` to read the stream into an `Uint8Array`.
|
|
6
|
-
|
|
7
|
-
```ts
|
|
8
|
-
import { Readable } from "stream";
|
|
9
|
-
const stream = Readable.from(["Hello, ", "world!"]);
|
|
10
|
-
const buf = await new Response(stream).bytes();
|
|
11
|
-
```
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: Convert a ReadableStream to an array of chunks
|
|
3
|
-
---
|
|
4
|
-
|
|
5
|
-
Bun provides a number of convenience functions for reading the contents of a [`ReadableStream`](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream) into different formats. The `Bun.readableStreamToArray` function reads the contents of a `ReadableStream` to an array of chunks.
|
|
6
|
-
|
|
7
|
-
```ts
|
|
8
|
-
const stream = new ReadableStream();
|
|
9
|
-
const str = await Bun.readableStreamToArray(stream);
|
|
10
|
-
```
|
|
11
|
-
|
|
12
|
-
---
|
|
13
|
-
|
|
14
|
-
See [Docs > API > Utils](https://bun.com/docs/api/utils#bun-readablestreamto) for documentation on Bun's other `ReadableStream` conversion functions.
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: Convert a ReadableStream to an ArrayBuffer
|
|
3
|
-
---
|
|
4
|
-
|
|
5
|
-
Bun provides a number of convenience functions for reading the contents of a [`ReadableStream`](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream) into different formats.
|
|
6
|
-
|
|
7
|
-
```ts
|
|
8
|
-
const stream = new ReadableStream();
|
|
9
|
-
const buf = await Bun.readableStreamToArrayBuffer(stream);
|
|
10
|
-
```
|
|
11
|
-
|
|
12
|
-
---
|
|
13
|
-
|
|
14
|
-
See [Docs > API > Utils](https://bun.com/docs/api/utils#bun-readablestreamto) for documentation on Bun's other `ReadableStream` conversion functions.
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: Convert a ReadableStream to a Blob
|
|
3
|
-
---
|
|
4
|
-
|
|
5
|
-
Bun provides a number of convenience functions for reading the contents of a [`ReadableStream`](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream) into different formats.
|
|
6
|
-
|
|
7
|
-
```ts
|
|
8
|
-
const stream = new ReadableStream();
|
|
9
|
-
const blob = await Bun.readableStreamToBlob(stream);
|
|
10
|
-
```
|
|
11
|
-
|
|
12
|
-
---
|
|
13
|
-
|
|
14
|
-
See [Docs > API > Utils](https://bun.com/docs/api/utils#bun-readablestreamto) for documentation on Bun's other `ReadableStream` conversion functions.
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: Convert a ReadableStream to a Buffer
|
|
3
|
-
---
|
|
4
|
-
|
|
5
|
-
Bun provides a number of convenience functions for reading the contents of a [`ReadableStream`](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream) into different formats. This snippet reads the contents of a `ReadableStream` to an [`ArrayBuffer`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer), then creates a [`Buffer`](https://nodejs.org/api/buffer.html) that points to it.
|
|
6
|
-
|
|
7
|
-
```ts
|
|
8
|
-
const stream = new ReadableStream();
|
|
9
|
-
const arrBuf = await Bun.readableStreamToArrayBuffer(stream);
|
|
10
|
-
const nodeBuf = Buffer.from(arrBuf);
|
|
11
|
-
```
|
|
12
|
-
|
|
13
|
-
---
|
|
14
|
-
|
|
15
|
-
See [Docs > API > Utils](https://bun.com/docs/api/utils#bun-readablestreamto) for documentation on Bun's other `ReadableStream` conversion functions.
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: Convert a ReadableStream to JSON
|
|
3
|
-
---
|
|
4
|
-
|
|
5
|
-
Bun provides a number of convenience functions for reading the contents of a [`ReadableStream`](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream) into different formats.
|
|
6
|
-
|
|
7
|
-
```ts
|
|
8
|
-
const stream = new ReadableStream();
|
|
9
|
-
const json = await Bun.readableStreamToJSON(stream);
|
|
10
|
-
```
|
|
11
|
-
|
|
12
|
-
---
|
|
13
|
-
|
|
14
|
-
See [Docs > API > Utils](https://bun.com/docs/api/utils#bun-readablestreamto) for documentation on Bun's other `ReadableStream` conversion functions.
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: Convert a ReadableStream to a string
|
|
3
|
-
---
|
|
4
|
-
|
|
5
|
-
Bun provides a number of convenience functions for reading the contents of a [`ReadableStream`](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream) into different formats.
|
|
6
|
-
|
|
7
|
-
```ts
|
|
8
|
-
const stream = new ReadableStream();
|
|
9
|
-
const str = await Bun.readableStreamToText(stream);
|
|
10
|
-
```
|
|
11
|
-
|
|
12
|
-
---
|
|
13
|
-
|
|
14
|
-
See [Docs > API > Utils](https://bun.com/docs/api/utils#bun-readablestreamto) for documentation on Bun's other `ReadableStream` conversion functions.
|