bun-types 1.3.2-canary.20251105T140650 → 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.
Files changed (308) hide show
  1. package/docs/README.md +28 -0
  2. package/package.json +1 -1
  3. package/docs/api/binary-data.md +0 -1038
  4. package/docs/api/cc.md +0 -197
  5. package/docs/api/color.md +0 -262
  6. package/docs/api/console.md +0 -57
  7. package/docs/api/cookie.md +0 -449
  8. package/docs/api/dns.md +0 -110
  9. package/docs/api/fetch.md +0 -463
  10. package/docs/api/ffi.md +0 -557
  11. package/docs/api/file-io.md +0 -366
  12. package/docs/api/file-system-router.md +0 -112
  13. package/docs/api/file.md +0 -19
  14. package/docs/api/glob.md +0 -178
  15. package/docs/api/globals.md +0 -387
  16. package/docs/api/hashing.md +0 -319
  17. package/docs/api/html-rewriter.md +0 -334
  18. package/docs/api/http.md +0 -1408
  19. package/docs/api/import-meta.md +0 -69
  20. package/docs/api/node-api.md +0 -14
  21. package/docs/api/redis.md +0 -597
  22. package/docs/api/s3.md +0 -850
  23. package/docs/api/secrets.md +0 -319
  24. package/docs/api/semver.md +0 -52
  25. package/docs/api/spawn.md +0 -582
  26. package/docs/api/sql.md +0 -1374
  27. package/docs/api/sqlite.md +0 -694
  28. package/docs/api/streams.md +0 -230
  29. package/docs/api/tcp.md +0 -221
  30. package/docs/api/transpiler.md +0 -276
  31. package/docs/api/udp.md +0 -123
  32. package/docs/api/utils.md +0 -891
  33. package/docs/api/websockets.md +0 -573
  34. package/docs/api/workers.md +0 -322
  35. package/docs/api/yaml.md +0 -668
  36. package/docs/benchmarks.md +0 -120
  37. package/docs/bun-flavored-toml.md +0 -42
  38. package/docs/bundler/css.md +0 -1028
  39. package/docs/bundler/css_modules.md +0 -145
  40. package/docs/bundler/executables.md +0 -626
  41. package/docs/bundler/fullstack.md +0 -418
  42. package/docs/bundler/hmr.md +0 -234
  43. package/docs/bundler/html.md +0 -349
  44. package/docs/bundler/index.md +0 -1735
  45. package/docs/bundler/intro.md +0 -75
  46. package/docs/bundler/loaders.md +0 -410
  47. package/docs/bundler/macros.md +0 -329
  48. package/docs/bundler/plugins.md +0 -449
  49. package/docs/bundler/vs-esbuild.md +0 -1127
  50. package/docs/cli/add.md +0 -173
  51. package/docs/cli/bun-completions.md +0 -3
  52. package/docs/cli/bun-create.md +0 -338
  53. package/docs/cli/bun-install.md +0 -349
  54. package/docs/cli/bun-upgrade.md +0 -39
  55. package/docs/cli/bunx.md +0 -89
  56. package/docs/cli/filter.md +0 -90
  57. package/docs/cli/info.md +0 -65
  58. package/docs/cli/init.md +0 -85
  59. package/docs/cli/install.md +0 -344
  60. package/docs/cli/link.md +0 -40
  61. package/docs/cli/outdated.md +0 -90
  62. package/docs/cli/patch-commit.md +0 -11
  63. package/docs/cli/pm.md +0 -285
  64. package/docs/cli/publish.md +0 -120
  65. package/docs/cli/remove.md +0 -7
  66. package/docs/cli/run.md +0 -261
  67. package/docs/cli/test.md +0 -397
  68. package/docs/cli/unlink.md +0 -9
  69. package/docs/cli/update.md +0 -129
  70. package/docs/cli/why.md +0 -67
  71. package/docs/contributing/upgrading-webkit.md +0 -57
  72. package/docs/ecosystem/elysia.md +0 -24
  73. package/docs/ecosystem/express.md +0 -37
  74. package/docs/ecosystem/hono.md +0 -18
  75. package/docs/ecosystem/react.md +0 -65
  76. package/docs/ecosystem/stric.md +0 -38
  77. package/docs/guides/binary/arraybuffer-to-array.md +0 -27
  78. package/docs/guides/binary/arraybuffer-to-blob.md +0 -24
  79. package/docs/guides/binary/arraybuffer-to-buffer.md +0 -25
  80. package/docs/guides/binary/arraybuffer-to-string.md +0 -15
  81. package/docs/guides/binary/arraybuffer-to-typedarray.md +0 -39
  82. package/docs/guides/binary/blob-to-arraybuffer.md +0 -14
  83. package/docs/guides/binary/blob-to-dataview.md +0 -14
  84. package/docs/guides/binary/blob-to-stream.md +0 -14
  85. package/docs/guides/binary/blob-to-string.md +0 -15
  86. package/docs/guides/binary/blob-to-typedarray.md +0 -14
  87. package/docs/guides/binary/buffer-to-arraybuffer.md +0 -14
  88. package/docs/guides/binary/buffer-to-blob.md +0 -14
  89. package/docs/guides/binary/buffer-to-readablestream.md +0 -41
  90. package/docs/guides/binary/buffer-to-string.md +0 -25
  91. package/docs/guides/binary/buffer-to-typedarray.md +0 -14
  92. package/docs/guides/binary/dataview-to-string.md +0 -15
  93. package/docs/guides/binary/typedarray-to-arraybuffer.md +0 -25
  94. package/docs/guides/binary/typedarray-to-blob.md +0 -16
  95. package/docs/guides/binary/typedarray-to-buffer.md +0 -14
  96. package/docs/guides/binary/typedarray-to-dataview.md +0 -14
  97. package/docs/guides/binary/typedarray-to-readablestream.md +0 -41
  98. package/docs/guides/binary/typedarray-to-string.md +0 -16
  99. package/docs/guides/deployment/railway.md +0 -157
  100. package/docs/guides/ecosystem/astro.md +0 -72
  101. package/docs/guides/ecosystem/discordjs.md +0 -77
  102. package/docs/guides/ecosystem/docker.md +0 -140
  103. package/docs/guides/ecosystem/drizzle.md +0 -185
  104. package/docs/guides/ecosystem/edgedb.md +0 -228
  105. package/docs/guides/ecosystem/elysia.md +0 -31
  106. package/docs/guides/ecosystem/express.md +0 -40
  107. package/docs/guides/ecosystem/hono.md +0 -39
  108. package/docs/guides/ecosystem/mongoose.md +0 -87
  109. package/docs/guides/ecosystem/neon-drizzle.md +0 -220
  110. package/docs/guides/ecosystem/neon-serverless-postgres.md +0 -55
  111. package/docs/guides/ecosystem/nextjs.md +0 -49
  112. package/docs/guides/ecosystem/nuxt.md +0 -56
  113. package/docs/guides/ecosystem/pm2.md +0 -57
  114. package/docs/guides/ecosystem/prisma.md +0 -141
  115. package/docs/guides/ecosystem/qwik.md +0 -107
  116. package/docs/guides/ecosystem/react.md +0 -50
  117. package/docs/guides/ecosystem/remix.md +0 -78
  118. package/docs/guides/ecosystem/render.md +0 -79
  119. package/docs/guides/ecosystem/sentry.md +0 -52
  120. package/docs/guides/ecosystem/solidstart.md +0 -58
  121. package/docs/guides/ecosystem/ssr-react.md +0 -51
  122. package/docs/guides/ecosystem/stric.md +0 -55
  123. package/docs/guides/ecosystem/sveltekit.md +0 -125
  124. package/docs/guides/ecosystem/systemd.md +0 -113
  125. package/docs/guides/ecosystem/vite.md +0 -71
  126. package/docs/guides/html-rewriter/extract-links.md +0 -68
  127. package/docs/guides/html-rewriter/extract-social-meta.md +0 -93
  128. package/docs/guides/http/cluster.md +0 -66
  129. package/docs/guides/http/fetch-unix.md +0 -33
  130. package/docs/guides/http/fetch.md +0 -24
  131. package/docs/guides/http/file-uploads.md +0 -94
  132. package/docs/guides/http/hot.md +0 -26
  133. package/docs/guides/http/proxy.md +0 -24
  134. package/docs/guides/http/server.md +0 -46
  135. package/docs/guides/http/simple.md +0 -18
  136. package/docs/guides/http/stream-file.md +0 -48
  137. package/docs/guides/http/stream-iterator.md +0 -47
  138. package/docs/guides/http/stream-node-streams-in-bun.md +0 -20
  139. package/docs/guides/http/tls.md +0 -30
  140. package/docs/guides/install/add-dev.md +0 -26
  141. package/docs/guides/install/add-git.md +0 -36
  142. package/docs/guides/install/add-optional.md +0 -25
  143. package/docs/guides/install/add-peer.md +0 -43
  144. package/docs/guides/install/add-tarball.md +0 -33
  145. package/docs/guides/install/add.md +0 -42
  146. package/docs/guides/install/azure-artifacts.md +0 -73
  147. package/docs/guides/install/cicd.md +0 -41
  148. package/docs/guides/install/custom-registry.md +0 -30
  149. package/docs/guides/install/from-npm-install-to-bun-install.md +0 -214
  150. package/docs/guides/install/git-diff-bun-lockfile.md +0 -44
  151. package/docs/guides/install/jfrog-artifactory.md +0 -28
  152. package/docs/guides/install/npm-alias.md +0 -23
  153. package/docs/guides/install/registry-scope.md +0 -38
  154. package/docs/guides/install/trusted.md +0 -46
  155. package/docs/guides/install/workspaces.md +0 -70
  156. package/docs/guides/install/yarnlock.md +0 -44
  157. package/docs/guides/process/argv.md +0 -58
  158. package/docs/guides/process/ctrl-c.md +0 -16
  159. package/docs/guides/process/ipc.md +0 -66
  160. package/docs/guides/process/nanoseconds.md +0 -13
  161. package/docs/guides/process/os-signals.md +0 -39
  162. package/docs/guides/process/spawn-stderr.md +0 -31
  163. package/docs/guides/process/spawn-stdout.md +0 -26
  164. package/docs/guides/process/spawn.md +0 -41
  165. package/docs/guides/process/stdin.md +0 -54
  166. package/docs/guides/read-file/arraybuffer.md +0 -28
  167. package/docs/guides/read-file/buffer.md +0 -19
  168. package/docs/guides/read-file/exists.md +0 -16
  169. package/docs/guides/read-file/json.md +0 -17
  170. package/docs/guides/read-file/mime.md +0 -20
  171. package/docs/guides/read-file/stream.md +0 -26
  172. package/docs/guides/read-file/string.md +0 -22
  173. package/docs/guides/read-file/uint8array.md +0 -21
  174. package/docs/guides/read-file/watch.md +0 -68
  175. package/docs/guides/runtime/build-time-constants.md +0 -293
  176. package/docs/guides/runtime/cicd.md +0 -43
  177. package/docs/guides/runtime/codesign-macos-executable.md +0 -56
  178. package/docs/guides/runtime/define-constant.md +0 -145
  179. package/docs/guides/runtime/delete-directory.md +0 -37
  180. package/docs/guides/runtime/delete-file.md +0 -19
  181. package/docs/guides/runtime/heap-snapshot.md +0 -26
  182. package/docs/guides/runtime/import-html.md +0 -15
  183. package/docs/guides/runtime/import-json.md +0 -44
  184. package/docs/guides/runtime/import-toml.md +0 -30
  185. package/docs/guides/runtime/import-yaml.md +0 -102
  186. package/docs/guides/runtime/read-env.md +0 -32
  187. package/docs/guides/runtime/set-env.md +0 -47
  188. package/docs/guides/runtime/shell.md +0 -40
  189. package/docs/guides/runtime/timezone.md +0 -35
  190. package/docs/guides/runtime/tsconfig-paths.md +0 -29
  191. package/docs/guides/runtime/typescript.md +0 -49
  192. package/docs/guides/runtime/vscode-debugger.md +0 -47
  193. package/docs/guides/runtime/web-debugger.md +0 -82
  194. package/docs/guides/streams/node-readable-to-arraybuffer.md +0 -11
  195. package/docs/guides/streams/node-readable-to-blob.md +0 -11
  196. package/docs/guides/streams/node-readable-to-json.md +0 -12
  197. package/docs/guides/streams/node-readable-to-string.md +0 -12
  198. package/docs/guides/streams/node-readable-to-uint8array.md +0 -11
  199. package/docs/guides/streams/to-array.md +0 -14
  200. package/docs/guides/streams/to-arraybuffer.md +0 -14
  201. package/docs/guides/streams/to-blob.md +0 -14
  202. package/docs/guides/streams/to-buffer.md +0 -15
  203. package/docs/guides/streams/to-json.md +0 -14
  204. package/docs/guides/streams/to-string.md +0 -14
  205. package/docs/guides/streams/to-typedarray.md +0 -22
  206. package/docs/guides/test/bail.md +0 -22
  207. package/docs/guides/test/coverage-threshold.md +0 -60
  208. package/docs/guides/test/coverage.md +0 -44
  209. package/docs/guides/test/happy-dom.md +0 -68
  210. package/docs/guides/test/migrate-from-jest.md +0 -143
  211. package/docs/guides/test/mock-clock.md +0 -48
  212. package/docs/guides/test/mock-functions.md +0 -68
  213. package/docs/guides/test/rerun-each.md +0 -14
  214. package/docs/guides/test/run-tests.md +0 -111
  215. package/docs/guides/test/skip-tests.md +0 -39
  216. package/docs/guides/test/snapshot.md +0 -95
  217. package/docs/guides/test/spy-on.md +0 -46
  218. package/docs/guides/test/svelte-test.md +0 -120
  219. package/docs/guides/test/testing-library.md +0 -92
  220. package/docs/guides/test/timeout.md +0 -15
  221. package/docs/guides/test/todo-tests.md +0 -67
  222. package/docs/guides/test/update-snapshots.md +0 -46
  223. package/docs/guides/test/watch-mode.md +0 -19
  224. package/docs/guides/util/base64.md +0 -15
  225. package/docs/guides/util/deep-equals.md +0 -39
  226. package/docs/guides/util/deflate.md +0 -18
  227. package/docs/guides/util/detect-bun.md +0 -23
  228. package/docs/guides/util/entrypoint.md +0 -17
  229. package/docs/guides/util/escape-html.md +0 -22
  230. package/docs/guides/util/file-url-to-path.md +0 -14
  231. package/docs/guides/util/gzip.md +0 -18
  232. package/docs/guides/util/hash-a-password.md +0 -54
  233. package/docs/guides/util/import-meta-dir.md +0 -13
  234. package/docs/guides/util/import-meta-file.md +0 -13
  235. package/docs/guides/util/import-meta-path.md +0 -13
  236. package/docs/guides/util/javascript-uuid.md +0 -23
  237. package/docs/guides/util/main.md +0 -32
  238. package/docs/guides/util/path-to-file-url.md +0 -14
  239. package/docs/guides/util/sleep.md +0 -22
  240. package/docs/guides/util/version.md +0 -21
  241. package/docs/guides/util/which-path-to-executable-bin.md +0 -15
  242. package/docs/guides/websocket/compression.md +0 -31
  243. package/docs/guides/websocket/context.md +0 -77
  244. package/docs/guides/websocket/pubsub.md +0 -41
  245. package/docs/guides/websocket/simple.md +0 -33
  246. package/docs/guides/write-file/append.md +0 -52
  247. package/docs/guides/write-file/basic.md +0 -44
  248. package/docs/guides/write-file/blob.md +0 -28
  249. package/docs/guides/write-file/cat.md +0 -17
  250. package/docs/guides/write-file/file-cp.md +0 -16
  251. package/docs/guides/write-file/filesink.md +0 -52
  252. package/docs/guides/write-file/response.md +0 -17
  253. package/docs/guides/write-file/stdout.md +0 -21
  254. package/docs/guides/write-file/stream.md +0 -17
  255. package/docs/guides/write-file/unlink.md +0 -16
  256. package/docs/index.md +0 -77
  257. package/docs/install/audit.md +0 -57
  258. package/docs/install/cache.md +0 -59
  259. package/docs/install/catalogs.md +0 -298
  260. package/docs/install/index.md +0 -248
  261. package/docs/install/isolated.md +0 -197
  262. package/docs/install/lifecycle.md +0 -46
  263. package/docs/install/lockfile.md +0 -58
  264. package/docs/install/npmrc.md +0 -105
  265. package/docs/install/overrides.md +0 -73
  266. package/docs/install/patch.md +0 -59
  267. package/docs/install/registries.md +0 -30
  268. package/docs/install/security-scanner-api.md +0 -81
  269. package/docs/install/workspaces.md +0 -114
  270. package/docs/installation.md +0 -327
  271. package/docs/project/asan.md +0 -124
  272. package/docs/project/benchmarking.md +0 -203
  273. package/docs/project/bindgen.md +0 -225
  274. package/docs/project/building-windows.md +0 -162
  275. package/docs/project/contributing.md +0 -347
  276. package/docs/project/internals/build-process-for-ci.md +0 -75
  277. package/docs/project/licensing.md +0 -73
  278. package/docs/project/roadmap.md +0 -87
  279. package/docs/quickstart.md +0 -157
  280. package/docs/runtime/autoimport.md +0 -94
  281. package/docs/runtime/bun-apis.md +0 -207
  282. package/docs/runtime/bunfig.md +0 -772
  283. package/docs/runtime/debugger.md +0 -325
  284. package/docs/runtime/env.md +0 -253
  285. package/docs/runtime/hot.md +0 -145
  286. package/docs/runtime/index.md +0 -312
  287. package/docs/runtime/jsx.md +0 -385
  288. package/docs/runtime/loaders.md +0 -130
  289. package/docs/runtime/modules.md +0 -320
  290. package/docs/runtime/nodejs-apis.md +0 -463
  291. package/docs/runtime/plugins.md +0 -561
  292. package/docs/runtime/shell.md +0 -605
  293. package/docs/runtime/typescript.md +0 -139
  294. package/docs/runtime/web-apis.md +0 -128
  295. package/docs/test/configuration.md +0 -154
  296. package/docs/test/coverage.md +0 -142
  297. package/docs/test/discovery.md +0 -85
  298. package/docs/test/dom.md +0 -75
  299. package/docs/test/examples/concurrent-test-glob.md +0 -132
  300. package/docs/test/hot.md +0 -15
  301. package/docs/test/lifecycle.md +0 -81
  302. package/docs/test/mocks.md +0 -313
  303. package/docs/test/reporters.md +0 -117
  304. package/docs/test/runtime-behavior.md +0 -95
  305. package/docs/test/snapshots.md +0 -68
  306. package/docs/test/time.md +0 -126
  307. package/docs/test/writing.md +0 -825
  308. package/docs/typescript.md +0 -53
package/docs/api/s3.md DELETED
@@ -1,850 +0,0 @@
1
- Production servers often read, upload, and write files to S3-compatible object storage services instead of the local filesystem. Historically, that means local filesystem APIs you use in development can't be used in production. When you use Bun, things are different.
2
-
3
- {% callout %}
4
-
5
- ### Bun's S3 API is fast
6
-
7
- {% image src="https://bun.com/bun-s3-node.gif" alt="Bun's S3 API is fast" caption="Left: Bun v1.1.44. Right: Node.js v23.6.0" /%}
8
-
9
- {% /callout %}
10
-
11
- Bun provides fast, native bindings for interacting with S3-compatible object storage services. Bun's S3 API is designed to be simple and feel similar to fetch's `Response` and `Blob` APIs (like Bun's local filesystem APIs).
12
-
13
- ```ts
14
- import { s3, write, S3Client } from "bun";
15
-
16
- // Bun.s3 reads environment variables for credentials
17
- // file() returns a lazy reference to a file on S3
18
- const metadata = s3.file("123.json");
19
-
20
- // Download from S3 as JSON
21
- const data = await metadata.json();
22
-
23
- // Upload to S3
24
- await write(metadata, JSON.stringify({ name: "John", age: 30 }));
25
-
26
- // Presign a URL (synchronous - no network request needed)
27
- const url = metadata.presign({
28
- acl: "public-read",
29
- expiresIn: 60 * 60 * 24, // 1 day
30
- });
31
-
32
- // Delete the file
33
- await metadata.delete();
34
- ```
35
-
36
- S3 is the [de facto standard](https://en.wikipedia.org/wiki/De_facto_standard) internet filesystem. Bun's S3 API works with S3-compatible storage services like:
37
-
38
- - AWS S3
39
- - Cloudflare R2
40
- - DigitalOcean Spaces
41
- - MinIO
42
- - Backblaze B2
43
- - ...and any other S3-compatible storage service
44
-
45
- ## Basic Usage
46
-
47
- There are several ways to interact with Bun's S3 API.
48
-
49
- ### `Bun.S3Client` & `Bun.s3`
50
-
51
- `Bun.s3` is equivalent to `new Bun.S3Client()`, relying on environment variables for credentials.
52
-
53
- To explicitly set credentials, pass them to the `Bun.S3Client` constructor.
54
-
55
- ```ts
56
- import { S3Client } from "bun";
57
-
58
- const client = new S3Client({
59
- accessKeyId: "your-access-key",
60
- secretAccessKey: "your-secret-key",
61
- bucket: "my-bucket",
62
- // sessionToken: "..."
63
- // acl: "public-read",
64
- // endpoint: "https://s3.us-east-1.amazonaws.com",
65
- // endpoint: "https://<account-id>.r2.cloudflarestorage.com", // Cloudflare R2
66
- // endpoint: "https://<region>.digitaloceanspaces.com", // DigitalOcean Spaces
67
- // endpoint: "http://localhost:9000", // MinIO
68
- });
69
-
70
- // Bun.s3 is a global singleton that is equivalent to `new Bun.S3Client()`
71
- ```
72
-
73
- ### Working with S3 Files
74
-
75
- The **`file`** method in `S3Client` returns a **lazy reference to a file on S3**.
76
-
77
- ```ts
78
- // A lazy reference to a file on S3
79
- const s3file: S3File = client.file("123.json");
80
- ```
81
-
82
- Like `Bun.file(path)`, the `S3Client`'s `file` method is synchronous. It does zero network requests until you call a method that depends on a network request.
83
-
84
- ### Reading files from S3
85
-
86
- If you've used the `fetch` API, you're familiar with the `Response` and `Blob` APIs. `S3File` extends `Blob`. The same methods that work on `Blob` also work on `S3File`.
87
-
88
- ```ts
89
- // Read an S3File as text
90
- const text = await s3file.text();
91
-
92
- // Read an S3File as JSON
93
- const json = await s3file.json();
94
-
95
- // Read an S3File as an ArrayBuffer
96
- const buffer = await s3file.arrayBuffer();
97
-
98
- // Get only the first 1024 bytes
99
- const partial = await s3file.slice(0, 1024).text();
100
-
101
- // Stream the file
102
- const stream = s3file.stream();
103
- for await (const chunk of stream) {
104
- console.log(chunk);
105
- }
106
- ```
107
-
108
- #### Memory optimization
109
-
110
- Methods like `text()`, `json()`, `bytes()`, or `arrayBuffer()` avoid duplicating the string or bytes in memory when possible.
111
-
112
- If the text happens to be ASCII, Bun directly transfers the string to JavaScriptCore (the engine) without transcoding and without duplicating the string in memory. When you use `.bytes()` or `.arrayBuffer()`, it will also avoid duplicating the bytes in memory.
113
-
114
- These helper methods not only simplify the API, they also make it faster.
115
-
116
- ### Writing & uploading files to S3
117
-
118
- Writing to S3 is just as simple.
119
-
120
- ```ts
121
- // Write a string (replacing the file)
122
- await s3file.write("Hello World!");
123
-
124
- // Write a Buffer (replacing the file)
125
- await s3file.write(Buffer.from("Hello World!"));
126
-
127
- // Write a Response (replacing the file)
128
- await s3file.write(new Response("Hello World!"));
129
-
130
- // Write with content type
131
- await s3file.write(JSON.stringify({ name: "John", age: 30 }), {
132
- type: "application/json",
133
- });
134
-
135
- // Write using a writer (streaming)
136
- const writer = s3file.writer({ type: "application/json" });
137
- writer.write("Hello");
138
- writer.write(" World!");
139
- await writer.end();
140
-
141
- // Write using Bun.write
142
- await Bun.write(s3file, "Hello World!");
143
- ```
144
-
145
- ### Working with large files (streams)
146
-
147
- Bun automatically handles multipart uploads for large files and provides streaming capabilities. The same API that works for local files also works for S3 files.
148
-
149
- ```ts
150
- // Write a large file
151
- const bigFile = Buffer.alloc(10 * 1024 * 1024); // 10MB
152
- const writer = s3file.writer({
153
- // Automatically retry on network errors up to 3 times
154
- retry: 3,
155
-
156
- // Queue up to 10 requests at a time
157
- queueSize: 10,
158
-
159
- // Upload in 5 MB chunks
160
- partSize: 5 * 1024 * 1024,
161
- });
162
- for (let i = 0; i < 10; i++) {
163
- writer.write(bigFile);
164
- await writer.flush();
165
- }
166
- await writer.end();
167
- ```
168
-
169
- ## Presigning URLs
170
-
171
- When your production service needs to let users upload files to your server, it's often more reliable for the user to upload directly to S3 instead of your server acting as an intermediary.
172
-
173
- To facilitate this, you can presign URLs for S3 files. This generates a URL with a signature that allows a user to securely upload that specific file to S3, without exposing your credentials or granting them unnecessary access to your bucket.
174
-
175
- The default behaviour is to generate a `GET` URL that expires in 24 hours. Bun attempts to infer the content type from the file extension. If inference is not possible, it will default to `application/octet-stream`.
176
-
177
- ```ts
178
- import { s3 } from "bun";
179
-
180
- // Generate a presigned URL that expires in 24 hours (default)
181
- const download = s3.presign("my-file.txt"); // GET, text/plain, expires in 24 hours
182
-
183
- const upload = s3.presign("my-file", {
184
- expiresIn: 3600, // 1 hour
185
- method: "PUT",
186
- type: "application/json", // No extension for inferring, so we can specify the content type to be JSON
187
- });
188
-
189
- // You can call .presign() if on a file reference, but avoid doing so
190
- // unless you already have a reference (to avoid memory usage).
191
- const myFile = s3.file("my-file.txt");
192
- const presignedFile = myFile.presign({
193
- expiresIn: 3600, // 1 hour
194
- });
195
- ```
196
-
197
- ### Setting ACLs
198
-
199
- To set an ACL (access control list) on a presigned URL, pass the `acl` option:
200
-
201
- ```ts
202
- const url = s3file.presign({
203
- acl: "public-read",
204
- expiresIn: 3600,
205
- });
206
- ```
207
-
208
- You can pass any of the following ACLs:
209
-
210
- | ACL | Explanation |
211
- | ----------------------------- | ------------------------------------------------------------------- |
212
- | `"public-read"` | The object is readable by the public. |
213
- | `"private"` | The object is readable only by the bucket owner. |
214
- | `"public-read-write"` | The object is readable and writable by the public. |
215
- | `"authenticated-read"` | The object is readable by the bucket owner and authenticated users. |
216
- | `"aws-exec-read"` | The object is readable by the AWS account that made the request. |
217
- | `"bucket-owner-read"` | The object is readable by the bucket owner. |
218
- | `"bucket-owner-full-control"` | The object is readable and writable by the bucket owner. |
219
- | `"log-delivery-write"` | The object is writable by AWS services used for log delivery. |
220
-
221
- ### Expiring URLs
222
-
223
- To set an expiration time for a presigned URL, pass the `expiresIn` option.
224
-
225
- ```ts
226
- const url = s3file.presign({
227
- // Seconds
228
- expiresIn: 3600, // 1 hour
229
-
230
- // access control list
231
- acl: "public-read",
232
-
233
- // HTTP method
234
- method: "PUT",
235
- });
236
- ```
237
-
238
- ### `method`
239
-
240
- To set the HTTP method for a presigned URL, pass the `method` option.
241
-
242
- ```ts
243
- const url = s3file.presign({
244
- method: "PUT",
245
- // method: "DELETE",
246
- // method: "GET",
247
- // method: "HEAD",
248
- // method: "POST",
249
- // method: "PUT",
250
- });
251
- ```
252
-
253
- ### `new Response(S3File)`
254
-
255
- To quickly redirect users to a presigned URL for an S3 file, pass an `S3File` instance to a `Response` object as the body.
256
-
257
- ```ts
258
- const response = new Response(s3file);
259
- console.log(response);
260
- ```
261
-
262
- This will automatically redirect the user to the presigned URL for the S3 file, saving you the memory, time, and bandwidth cost of downloading the file to your server and sending it back to the user.
263
-
264
- ```ts
265
- Response (0 KB) {
266
- ok: false,
267
- url: "",
268
- status: 302,
269
- statusText: "",
270
- headers: Headers {
271
- "location": "https://<account-id>.r2.cloudflarestorage.com/...",
272
- },
273
- redirected: true,
274
- bodyUsed: false
275
- }
276
- ```
277
-
278
- ## Support for S3-Compatible Services
279
-
280
- Bun's S3 implementation works with any S3-compatible storage service. Just specify the appropriate endpoint:
281
-
282
- ### Using Bun's S3Client with AWS S3
283
-
284
- AWS S3 is the default. You can also pass a `region` option instead of an `endpoint` option for AWS S3.
285
-
286
- ```ts
287
- import { S3Client } from "bun";
288
-
289
- // AWS S3
290
- const s3 = new S3Client({
291
- accessKeyId: "access-key",
292
- secretAccessKey: "secret-key",
293
- bucket: "my-bucket",
294
- // endpoint: "https://s3.us-east-1.amazonaws.com",
295
- // region: "us-east-1",
296
- });
297
- ```
298
-
299
- ### Using Bun's S3Client with Google Cloud Storage
300
-
301
- To use Bun's S3 client with [Google Cloud Storage](https://cloud.google.com/storage), set `endpoint` to `"https://storage.googleapis.com"` in the `S3Client` constructor.
302
-
303
- ```ts
304
- import { S3Client } from "bun";
305
-
306
- // Google Cloud Storage
307
- const gcs = new S3Client({
308
- accessKeyId: "access-key",
309
- secretAccessKey: "secret-key",
310
- bucket: "my-bucket",
311
- endpoint: "https://storage.googleapis.com",
312
- });
313
- ```
314
-
315
- ### Using Bun's S3Client with Cloudflare R2
316
-
317
- To use Bun's S3 client with [Cloudflare R2](https://developers.cloudflare.com/r2/), set `endpoint` to the R2 endpoint in the `S3Client` constructor. The R2 endpoint includes your account ID.
318
-
319
- ```ts
320
- import { S3Client } from "bun";
321
-
322
- // CloudFlare R2
323
- const r2 = new S3Client({
324
- accessKeyId: "access-key",
325
- secretAccessKey: "secret-key",
326
- bucket: "my-bucket",
327
- endpoint: "https://<account-id>.r2.cloudflarestorage.com",
328
- });
329
- ```
330
-
331
- ### Using Bun's S3Client with DigitalOcean Spaces
332
-
333
- To use Bun's S3 client with [DigitalOcean Spaces](https://www.digitalocean.com/products/spaces/), set `endpoint` to the DigitalOcean Spaces endpoint in the `S3Client` constructor.
334
-
335
- ```ts
336
- import { S3Client } from "bun";
337
-
338
- const spaces = new S3Client({
339
- accessKeyId: "access-key",
340
- secretAccessKey: "secret-key",
341
- bucket: "my-bucket",
342
- // region: "nyc3",
343
- endpoint: "https://<region>.digitaloceanspaces.com",
344
- });
345
- ```
346
-
347
- ### Using Bun's S3Client with MinIO
348
-
349
- To use Bun's S3 client with [MinIO](https://min.io/), set `endpoint` to the URL that MinIO is running on in the `S3Client` constructor.
350
-
351
- ```ts
352
- import { S3Client } from "bun";
353
-
354
- const minio = new S3Client({
355
- accessKeyId: "access-key",
356
- secretAccessKey: "secret-key",
357
- bucket: "my-bucket",
358
-
359
- // Make sure to use the correct endpoint URL
360
- // It might not be localhost in production!
361
- endpoint: "http://localhost:9000",
362
- });
363
- ```
364
-
365
- ### Using Bun's S3Client with supabase
366
-
367
- To use Bun's S3 client with [supabase](https://supabase.com/), set `endpoint` to the supabase endpoint in the `S3Client` constructor. The supabase endpoint includes your account ID and /storage/v1/s3 path. Make sure to set Enable connection via S3 protocol on in the supabase dashboard in https://supabase.com/dashboard/project/<account-id>/settings/storage and to set the region informed in the same section.
368
-
369
- ```ts
370
- import { S3Client } from "bun";
371
-
372
- const supabase = new S3Client({
373
- accessKeyId: "access-key",
374
- secretAccessKey: "secret-key",
375
- bucket: "my-bucket",
376
- region: "us-west-1",
377
- endpoint: "https://<account-id>.supabase.co/storage/v1/s3/storage",
378
- });
379
- ```
380
-
381
- ### Using Bun's S3Client with S3 Virtual Hosted-Style endpoints
382
-
383
- When using a S3 Virtual Hosted-Style endpoint, you need to set the `virtualHostedStyle` option to `true` and if no endpoint is provided, Bun will use region and bucket to infer the endpoint to AWS S3, if no region is provided it will use `us-east-1`. If you provide a the endpoint, there are no need to provide the bucket name.
384
-
385
- ```ts
386
- import { S3Client } from "bun";
387
-
388
- // AWS S3 endpoint inferred from region and bucket
389
- const s3 = new S3Client({
390
- accessKeyId: "access-key",
391
- secretAccessKey: "secret-key",
392
- bucket: "my-bucket",
393
- virtualHostedStyle: true,
394
- // endpoint: "https://my-bucket.s3.us-east-1.amazonaws.com",
395
- // region: "us-east-1",
396
- });
397
-
398
- // AWS S3
399
- const s3WithEndpoint = new S3Client({
400
- accessKeyId: "access-key",
401
- secretAccessKey: "secret-key",
402
- endpoint: "https://<bucket-name>.s3.<region>.amazonaws.com",
403
- virtualHostedStyle: true,
404
- });
405
-
406
- // Cloudflare R2
407
- const r2WithEndpoint = new S3Client({
408
- accessKeyId: "access-key",
409
- secretAccessKey: "secret-key",
410
- endpoint: "https://<bucket-name>.<account-id>.r2.cloudflarestorage.com",
411
- virtualHostedStyle: true,
412
- });
413
- ```
414
-
415
- ## Credentials
416
-
417
- Credentials are one of the hardest parts of using S3, and we've tried to make it as easy as possible. By default, Bun reads the following environment variables for credentials.
418
-
419
- | Option name | Environment variable |
420
- | ----------------- | ---------------------- |
421
- | `accessKeyId` | `S3_ACCESS_KEY_ID` |
422
- | `secretAccessKey` | `S3_SECRET_ACCESS_KEY` |
423
- | `region` | `S3_REGION` |
424
- | `endpoint` | `S3_ENDPOINT` |
425
- | `bucket` | `S3_BUCKET` |
426
- | `sessionToken` | `S3_SESSION_TOKEN` |
427
-
428
- If the `S3_*` environment variable is not set, Bun will also check for the `AWS_*` environment variable, for each of the above options.
429
-
430
- | Option name | Fallback environment variable |
431
- | ----------------- | ----------------------------- |
432
- | `accessKeyId` | `AWS_ACCESS_KEY_ID` |
433
- | `secretAccessKey` | `AWS_SECRET_ACCESS_KEY` |
434
- | `region` | `AWS_REGION` |
435
- | `endpoint` | `AWS_ENDPOINT` |
436
- | `bucket` | `AWS_BUCKET` |
437
- | `sessionToken` | `AWS_SESSION_TOKEN` |
438
-
439
- These environment variables are read from [`.env` files](/docs/runtime/env) or from the process environment at initialization time (`process.env` is not used for this).
440
-
441
- These defaults are overridden by the options you pass to `s3.file(credentials)`, `new Bun.S3Client(credentials)`, or any of the methods that accept credentials. So if, for example, you use the same credentials for different buckets, you can set the credentials once in your `.env` file and then pass `bucket: "my-bucket"` to the `s3.file()` function without having to specify all the credentials again.
442
-
443
- ### `S3Client` objects
444
-
445
- When you're not using environment variables or using multiple buckets, you can create a `S3Client` object to explicitly set credentials.
446
-
447
- ```ts
448
- import { S3Client } from "bun";
449
-
450
- const client = new S3Client({
451
- accessKeyId: "your-access-key",
452
- secretAccessKey: "your-secret-key",
453
- bucket: "my-bucket",
454
- // sessionToken: "..."
455
- endpoint: "https://s3.us-east-1.amazonaws.com",
456
- // endpoint: "https://<account-id>.r2.cloudflarestorage.com", // Cloudflare R2
457
- // endpoint: "http://localhost:9000", // MinIO
458
- });
459
-
460
- // Write using a Response
461
- await file.write(new Response("Hello World!"));
462
-
463
- // Presign a URL
464
- const url = file.presign({
465
- expiresIn: 60 * 60 * 24, // 1 day
466
- acl: "public-read",
467
- });
468
-
469
- // Delete the file
470
- await file.delete();
471
- ```
472
-
473
- ### `S3Client.prototype.write`
474
-
475
- To upload or write a file to S3, call `write` on the `S3Client` instance.
476
-
477
- ```ts
478
- const client = new Bun.S3Client({
479
- accessKeyId: "your-access-key",
480
- secretAccessKey: "your-secret-key",
481
- endpoint: "https://s3.us-east-1.amazonaws.com",
482
- bucket: "my-bucket",
483
- });
484
- await client.write("my-file.txt", "Hello World!");
485
- await client.write("my-file.txt", new Response("Hello World!"));
486
-
487
- // equivalent to
488
- // await client.file("my-file.txt").write("Hello World!");
489
- ```
490
-
491
- ### `S3Client.prototype.delete`
492
-
493
- To delete a file from S3, call `delete` on the `S3Client` instance.
494
-
495
- ```ts
496
- const client = new Bun.S3Client({
497
- accessKeyId: "your-access-key",
498
- secretAccessKey: "your-secret-key",
499
- bucket: "my-bucket",
500
- });
501
-
502
- await client.delete("my-file.txt");
503
- // equivalent to
504
- // await client.file("my-file.txt").delete();
505
- ```
506
-
507
- ### `S3Client.prototype.exists`
508
-
509
- To check if a file exists in S3, call `exists` on the `S3Client` instance.
510
-
511
- ```ts
512
- const client = new Bun.S3Client({
513
- accessKeyId: "your-access-key",
514
- secretAccessKey: "your-secret-key",
515
- bucket: "my-bucket",
516
- });
517
-
518
- const exists = await client.exists("my-file.txt");
519
- // equivalent to
520
- // const exists = await client.file("my-file.txt").exists();
521
- ```
522
-
523
- ## `S3File`
524
-
525
- `S3File` instances are created by calling the `S3Client` instance method or the `s3.file()` function. Like `Bun.file()`, `S3File` instances are lazy. They don't refer to something that necessarily exists at the time of creation. That's why all the methods that don't involve network requests are fully synchronous.
526
-
527
- ```ts
528
- interface S3File extends Blob {
529
- slice(start: number, end?: number): S3File;
530
- exists(): Promise<boolean>;
531
- unlink(): Promise<void>;
532
- presign(options: S3Options): string;
533
- text(): Promise<string>;
534
- json(): Promise<any>;
535
- bytes(): Promise<Uint8Array>;
536
- arrayBuffer(): Promise<ArrayBuffer>;
537
- stream(options: S3Options): ReadableStream;
538
- write(
539
- data:
540
- | string
541
- | Uint8Array
542
- | ArrayBuffer
543
- | Blob
544
- | ReadableStream
545
- | Response
546
- | Request,
547
- options?: BlobPropertyBag,
548
- ): Promise<number>;
549
-
550
- exists(options?: S3Options): Promise<boolean>;
551
- unlink(options?: S3Options): Promise<void>;
552
- delete(options?: S3Options): Promise<void>;
553
- presign(options?: S3Options): string;
554
-
555
- stat(options?: S3Options): Promise<S3Stat>;
556
- /**
557
- * Size is not synchronously available because it requires a network request.
558
- *
559
- * @deprecated Use `stat()` instead.
560
- */
561
- size: NaN;
562
-
563
- // ... more omitted for brevity
564
- }
565
- ```
566
-
567
- Like `Bun.file()`, `S3File` extends [`Blob`](https://developer.mozilla.org/en-US/docs/Web/API/Blob), so all the methods that are available on `Blob` are also available on `S3File`. The same API for reading data from a local file is also available for reading data from S3.
568
-
569
- | Method | Output |
570
- | ---------------------------- | ---------------- |
571
- | `await s3File.text()` | `string` |
572
- | `await s3File.bytes()` | `Uint8Array` |
573
- | `await s3File.json()` | `JSON` |
574
- | `await s3File.stream()` | `ReadableStream` |
575
- | `await s3File.arrayBuffer()` | `ArrayBuffer` |
576
-
577
- That means using `S3File` instances with `fetch()`, `Response`, and other web APIs that accept `Blob` instances just works.
578
-
579
- ### Partial reads with `slice`
580
-
581
- To read a partial range of a file, you can use the `slice` method.
582
-
583
- ```ts
584
- const partial = s3file.slice(0, 1024);
585
-
586
- // Read the partial range as a Uint8Array
587
- const bytes = await partial.bytes();
588
-
589
- // Read the partial range as a string
590
- const text = await partial.text();
591
- ```
592
-
593
- Internally, this works by using the HTTP `Range` header to request only the bytes you want. This `slice` method is the same as [`Blob.prototype.slice`](https://developer.mozilla.org/en-US/docs/Web/API/Blob/slice).
594
-
595
- ### Deleting files from S3
596
-
597
- To delete a file from S3, you can use the `delete` method.
598
-
599
- ```ts
600
- await s3file.delete();
601
- // await s3File.unlink();
602
- ```
603
-
604
- `delete` is the same as `unlink`.
605
-
606
- ## Error codes
607
-
608
- When Bun's S3 API throws an error, it will have a `code` property that matches one of the following values:
609
-
610
- - `ERR_S3_MISSING_CREDENTIALS`
611
- - `ERR_S3_INVALID_METHOD`
612
- - `ERR_S3_INVALID_PATH`
613
- - `ERR_S3_INVALID_ENDPOINT`
614
- - `ERR_S3_INVALID_SIGNATURE`
615
- - `ERR_S3_INVALID_SESSION_TOKEN`
616
-
617
- When the S3 Object Storage service returns an error (that is, not Bun), it will be an `S3Error` instance (an `Error` instance with the name `"S3Error"`).
618
-
619
- ## `S3Client` static methods
620
-
621
- The `S3Client` class provides several static methods for interacting with S3.
622
-
623
- ### `S3Client.write` (static)
624
-
625
- To write data directly to a path in the bucket, you can use the `S3Client.write` static method.
626
-
627
- ```ts
628
- import { S3Client } from "bun";
629
-
630
- const credentials = {
631
- accessKeyId: "your-access-key",
632
- secretAccessKey: "your-secret-key",
633
- bucket: "my-bucket",
634
- // endpoint: "https://s3.us-east-1.amazonaws.com",
635
- // endpoint: "https://<account-id>.r2.cloudflarestorage.com", // Cloudflare R2
636
- };
637
-
638
- // Write string
639
- await S3Client.write("my-file.txt", "Hello World");
640
-
641
- // Write JSON with type
642
- await S3Client.write("data.json", JSON.stringify({ hello: "world" }), {
643
- ...credentials,
644
- type: "application/json",
645
- });
646
-
647
- // Write from fetch
648
- const res = await fetch("https://example.com/data");
649
- await S3Client.write("data.bin", res, credentials);
650
-
651
- // Write with ACL
652
- await S3Client.write("public.html", html, {
653
- ...credentials,
654
- acl: "public-read",
655
- type: "text/html",
656
- });
657
- ```
658
-
659
- This is equivalent to calling `new S3Client(credentials).write("my-file.txt", "Hello World")`.
660
-
661
- ### `S3Client.presign` (static)
662
-
663
- To generate a presigned URL for an S3 file, you can use the `S3Client.presign` static method.
664
-
665
- ```ts
666
- import { S3Client } from "bun";
667
-
668
- const credentials = {
669
- accessKeyId: "your-access-key",
670
- secretAccessKey: "your-secret-key",
671
- bucket: "my-bucket",
672
- // endpoint: "https://s3.us-east-1.amazonaws.com",
673
- // endpoint: "https://<account-id>.r2.cloudflarestorage.com", // Cloudflare R2
674
- };
675
-
676
- const url = S3Client.presign("my-file.txt", {
677
- ...credentials,
678
- expiresIn: 3600,
679
- });
680
- ```
681
-
682
- This is equivalent to calling `new S3Client(credentials).presign("my-file.txt", { expiresIn: 3600 })`.
683
-
684
- ### `S3Client.list` (static)
685
-
686
- To list some or all (up to 1,000) objects in a bucket, you can use the `S3Client.list` static method.
687
-
688
- ```ts
689
- import { S3Client } from "bun";
690
-
691
- const credentials = {
692
- accessKeyId: "your-access-key",
693
- secretAccessKey: "your-secret-key",
694
- bucket: "my-bucket",
695
- // endpoint: "https://s3.us-east-1.amazonaws.com",
696
- // endpoint: "https://<account-id>.r2.cloudflarestorage.com", // Cloudflare R2
697
- };
698
-
699
- // List (up to) 1000 objects in the bucket
700
- const allObjects = await S3Client.list(null, credentials);
701
-
702
- // List (up to) 500 objects under `uploads/` prefix, with owner field for each object
703
- const uploads = await S3Client.list({
704
- prefix: 'uploads/',
705
- maxKeys: 500,
706
- fetchOwner: true,
707
- }, credentials);
708
-
709
- // Check if more results are available
710
- if (uploads.isTruncated) {
711
- // List next batch of objects under `uploads/` prefix
712
- const moreUploads = await S3Client.list({
713
- prefix: 'uploads/',
714
- maxKeys: 500,
715
- startAfter: uploads.contents!.at(-1).key
716
- fetchOwner: true,
717
- }, credentials);
718
- }
719
- ```
720
-
721
- This is equivalent to calling `new S3Client(credentials).list()`.
722
-
723
- ### `S3Client.exists` (static)
724
-
725
- To check if an S3 file exists, you can use the `S3Client.exists` static method.
726
-
727
- ```ts
728
- import { S3Client } from "bun";
729
-
730
- const credentials = {
731
- accessKeyId: "your-access-key",
732
- secretAccessKey: "your-secret-key",
733
- bucket: "my-bucket",
734
- // endpoint: "https://s3.us-east-1.amazonaws.com",
735
- // endpoint: "https://<account-id>.r2.cloudflarestorage.com", // Cloudflare R2
736
- };
737
-
738
- const exists = await S3Client.exists("my-file.txt", credentials);
739
- ```
740
-
741
- The same method also works on `S3File` instances.
742
-
743
- ```ts
744
- import { s3 } from "bun";
745
-
746
- const s3file = s3.file("my-file.txt", {
747
- ...credentials,
748
- });
749
- const exists = await s3file.exists();
750
- ```
751
-
752
- ### `S3Client.size` (static)
753
-
754
- To quickly check the size of S3 file without downloading it, you can use the `S3Client.size` static method.
755
-
756
- ```ts
757
- import { S3Client } from "bun";
758
-
759
- const credentials = {
760
- accessKeyId: "your-access-key",
761
- secretAccessKey: "your-secret-key",
762
- bucket: "my-bucket",
763
- // endpoint: "https://s3.us-east-1.amazonaws.com",
764
- // endpoint: "https://<account-id>.r2.cloudflarestorage.com", // Cloudflare R2
765
- };
766
-
767
- const bytes = await S3Client.size("my-file.txt", credentials);
768
- ```
769
-
770
- This is equivalent to calling `new S3Client(credentials).size("my-file.txt")`.
771
-
772
- ### `S3Client.stat` (static)
773
-
774
- To get the size, etag, and other metadata of an S3 file, you can use the `S3Client.stat` static method.
775
-
776
- ```ts
777
- import { S3Client } from "bun";
778
-
779
- const credentials = {
780
- accessKeyId: "your-access-key",
781
- secretAccessKey: "your-secret-key",
782
- bucket: "my-bucket",
783
- // endpoint: "https://s3.us-east-1.amazonaws.com",
784
- // endpoint: "https://<account-id>.r2.cloudflarestorage.com", // Cloudflare R2
785
- };
786
-
787
- const stat = await S3Client.stat("my-file.txt", credentials);
788
- // {
789
- // etag: "\"7a30b741503c0b461cc14157e2df4ad8\"",
790
- // lastModified: 2025-01-07T00:19:10.000Z,
791
- // size: 1024,
792
- // type: "text/plain;charset=utf-8",
793
- // }
794
- ```
795
-
796
- ### `S3Client.delete` (static)
797
-
798
- To delete an S3 file, you can use the `S3Client.delete` static method.
799
-
800
- ```ts
801
- import { S3Client } from "bun";
802
-
803
- const credentials = {
804
- accessKeyId: "your-access-key",
805
- secretAccessKey: "your-secret-key",
806
- bucket: "my-bucket",
807
- // endpoint: "https://s3.us-east-1.amazonaws.com",
808
- };
809
-
810
- await S3Client.delete("my-file.txt", credentials);
811
- // equivalent to
812
- // await new S3Client(credentials).delete("my-file.txt");
813
-
814
- // S3Client.unlink is alias of S3Client.delete
815
- await S3Client.unlink("my-file.txt", credentials);
816
- ```
817
-
818
- ## `s3://` protocol
819
-
820
- To make it easier to use the same code for local files and S3 files, the `s3://` protocol is supported in `fetch` and `Bun.file()`.
821
-
822
- ```ts
823
- const response = await fetch("s3://my-bucket/my-file.txt");
824
- const file = Bun.file("s3://my-bucket/my-file.txt");
825
- ```
826
-
827
- You can additionally pass `s3` options to the `fetch` and `Bun.file` functions.
828
-
829
- ```ts
830
- const response = await fetch("s3://my-bucket/my-file.txt", {
831
- s3: {
832
- accessKeyId: "your-access-key",
833
- secretAccessKey: "your-secret-key",
834
- endpoint: "https://s3.us-east-1.amazonaws.com",
835
- },
836
- headers: {
837
- "range": "bytes=0-1023",
838
- },
839
- });
840
- ```
841
-
842
- ### UTF-8, UTF-16, and BOM (byte order mark)
843
-
844
- Like `Response` and `Blob`, `S3File` assumes UTF-8 encoding by default.
845
-
846
- When calling one of the `text()` or `json()` methods on an `S3File`:
847
-
848
- - When a UTF-16 byte order mark (BOM) is detected, it will be treated as UTF-16. JavaScriptCore natively supports UTF-16, so it skips the UTF-8 transcoding process (and strips the BOM). This is mostly good, but it does mean if you have invalid surrogate pairs characters in your UTF-16 string, they will be passed through to JavaScriptCore (same as source code).
849
- - When a UTF-8 BOM is detected, it gets stripped before the string is passed to JavaScriptCore and invalid UTF-8 codepoints are replaced with the Unicode replacement character (`\uFFFD`).
850
- - UTF-32 is not supported.