@depup/bun-types 1.3.11-depup.0

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 (361) hide show
  1. package/CLAUDE.md +105 -0
  2. package/README.md +25 -0
  3. package/bun.d.ts +8712 -0
  4. package/bun.ns.d.ts +5 -0
  5. package/bundle.d.ts +74 -0
  6. package/changes.json +5 -0
  7. package/deprecated.d.ts +184 -0
  8. package/devserver.d.ts +187 -0
  9. package/docs/README.md +28 -0
  10. package/docs/bundler/bytecode.mdx +447 -0
  11. package/docs/bundler/css.mdx +1024 -0
  12. package/docs/bundler/esbuild.mdx +304 -0
  13. package/docs/bundler/executables.mdx +1318 -0
  14. package/docs/bundler/fullstack.mdx +1086 -0
  15. package/docs/bundler/hot-reloading.mdx +229 -0
  16. package/docs/bundler/html-static.mdx +498 -0
  17. package/docs/bundler/index.mdx +1840 -0
  18. package/docs/bundler/loaders.mdx +451 -0
  19. package/docs/bundler/macros.mdx +328 -0
  20. package/docs/bundler/minifier.mdx +1286 -0
  21. package/docs/bundler/plugins.mdx +477 -0
  22. package/docs/bundler/standalone-html.mdx +314 -0
  23. package/docs/feedback.mdx +75 -0
  24. package/docs/guides/binary/arraybuffer-to-array.mdx +29 -0
  25. package/docs/guides/binary/arraybuffer-to-blob.mdx +26 -0
  26. package/docs/guides/binary/arraybuffer-to-buffer.mdx +27 -0
  27. package/docs/guides/binary/arraybuffer-to-string.mdx +17 -0
  28. package/docs/guides/binary/arraybuffer-to-typedarray.mdx +41 -0
  29. package/docs/guides/binary/blob-to-arraybuffer.mdx +16 -0
  30. package/docs/guides/binary/blob-to-dataview.mdx +16 -0
  31. package/docs/guides/binary/blob-to-stream.mdx +16 -0
  32. package/docs/guides/binary/blob-to-string.mdx +17 -0
  33. package/docs/guides/binary/blob-to-typedarray.mdx +16 -0
  34. package/docs/guides/binary/buffer-to-arraybuffer.mdx +16 -0
  35. package/docs/guides/binary/buffer-to-blob.mdx +16 -0
  36. package/docs/guides/binary/buffer-to-readablestream.mdx +43 -0
  37. package/docs/guides/binary/buffer-to-string.mdx +27 -0
  38. package/docs/guides/binary/buffer-to-typedarray.mdx +16 -0
  39. package/docs/guides/binary/dataview-to-string.mdx +17 -0
  40. package/docs/guides/binary/typedarray-to-arraybuffer.mdx +27 -0
  41. package/docs/guides/binary/typedarray-to-blob.mdx +18 -0
  42. package/docs/guides/binary/typedarray-to-buffer.mdx +16 -0
  43. package/docs/guides/binary/typedarray-to-dataview.mdx +16 -0
  44. package/docs/guides/binary/typedarray-to-readablestream.mdx +43 -0
  45. package/docs/guides/binary/typedarray-to-string.mdx +18 -0
  46. package/docs/guides/deployment/aws-lambda.mdx +204 -0
  47. package/docs/guides/deployment/digital-ocean.mdx +161 -0
  48. package/docs/guides/deployment/google-cloud-run.mdx +194 -0
  49. package/docs/guides/deployment/railway.mdx +145 -0
  50. package/docs/guides/deployment/render.mdx +82 -0
  51. package/docs/guides/deployment/vercel.mdx +97 -0
  52. package/docs/guides/ecosystem/astro.mdx +82 -0
  53. package/docs/guides/ecosystem/discordjs.mdx +80 -0
  54. package/docs/guides/ecosystem/docker.mdx +151 -0
  55. package/docs/guides/ecosystem/drizzle.mdx +195 -0
  56. package/docs/guides/ecosystem/elysia.mdx +31 -0
  57. package/docs/guides/ecosystem/express.mdx +43 -0
  58. package/docs/guides/ecosystem/gel.mdx +261 -0
  59. package/docs/guides/ecosystem/hono.mdx +47 -0
  60. package/docs/guides/ecosystem/mongoose.mdx +92 -0
  61. package/docs/guides/ecosystem/neon-drizzle.mdx +234 -0
  62. package/docs/guides/ecosystem/neon-serverless-postgres.mdx +60 -0
  63. package/docs/guides/ecosystem/nextjs.mdx +103 -0
  64. package/docs/guides/ecosystem/nuxt.mdx +96 -0
  65. package/docs/guides/ecosystem/pm2.mdx +55 -0
  66. package/docs/guides/ecosystem/prisma-postgres.mdx +169 -0
  67. package/docs/guides/ecosystem/prisma.mdx +164 -0
  68. package/docs/guides/ecosystem/qwik.mdx +114 -0
  69. package/docs/guides/ecosystem/react.mdx +52 -0
  70. package/docs/guides/ecosystem/remix.mdx +97 -0
  71. package/docs/guides/ecosystem/sentry.mdx +54 -0
  72. package/docs/guides/ecosystem/solidstart.mdx +62 -0
  73. package/docs/guides/ecosystem/ssr-react.mdx +49 -0
  74. package/docs/guides/ecosystem/stric.mdx +54 -0
  75. package/docs/guides/ecosystem/sveltekit.mdx +138 -0
  76. package/docs/guides/ecosystem/systemd.mdx +114 -0
  77. package/docs/guides/ecosystem/tanstack-start.mdx +791 -0
  78. package/docs/guides/ecosystem/upstash.mdx +87 -0
  79. package/docs/guides/ecosystem/vite.mdx +77 -0
  80. package/docs/guides/html-rewriter/extract-links.mdx +71 -0
  81. package/docs/guides/html-rewriter/extract-social-meta.mdx +97 -0
  82. package/docs/guides/http/cluster.mdx +69 -0
  83. package/docs/guides/http/fetch-unix.mdx +35 -0
  84. package/docs/guides/http/fetch.mdx +26 -0
  85. package/docs/guides/http/file-uploads.mdx +97 -0
  86. package/docs/guides/http/hot.mdx +28 -0
  87. package/docs/guides/http/proxy.mdx +50 -0
  88. package/docs/guides/http/server.mdx +48 -0
  89. package/docs/guides/http/simple.mdx +20 -0
  90. package/docs/guides/http/sse.mdx +91 -0
  91. package/docs/guides/http/stream-file.mdx +50 -0
  92. package/docs/guides/http/stream-iterator.mdx +49 -0
  93. package/docs/guides/http/stream-node-streams-in-bun.mdx +22 -0
  94. package/docs/guides/http/tls.mdx +32 -0
  95. package/docs/guides/index.mdx +10 -0
  96. package/docs/guides/install/add-dev.mdx +28 -0
  97. package/docs/guides/install/add-git.mdx +40 -0
  98. package/docs/guides/install/add-optional.mdx +27 -0
  99. package/docs/guides/install/add-peer.mdx +45 -0
  100. package/docs/guides/install/add-tarball.mdx +35 -0
  101. package/docs/guides/install/add.mdx +44 -0
  102. package/docs/guides/install/azure-artifacts.mdx +76 -0
  103. package/docs/guides/install/cicd.mdx +43 -0
  104. package/docs/guides/install/custom-registry.mdx +32 -0
  105. package/docs/guides/install/from-npm-install-to-bun-install.mdx +230 -0
  106. package/docs/guides/install/git-diff-bun-lockfile.mdx +48 -0
  107. package/docs/guides/install/jfrog-artifactory.mdx +28 -0
  108. package/docs/guides/install/npm-alias.mdx +25 -0
  109. package/docs/guides/install/registry-scope.mdx +40 -0
  110. package/docs/guides/install/trusted.mdx +52 -0
  111. package/docs/guides/install/workspaces.mdx +70 -0
  112. package/docs/guides/install/yarnlock.mdx +51 -0
  113. package/docs/guides/process/argv.mdx +66 -0
  114. package/docs/guides/process/ctrl-c.mdx +18 -0
  115. package/docs/guides/process/ipc.mdx +69 -0
  116. package/docs/guides/process/nanoseconds.mdx +15 -0
  117. package/docs/guides/process/os-signals.mdx +31 -0
  118. package/docs/guides/process/spawn-stderr.mdx +34 -0
  119. package/docs/guides/process/spawn-stdout.mdx +28 -0
  120. package/docs/guides/process/spawn.mdx +43 -0
  121. package/docs/guides/process/stdin.mdx +62 -0
  122. package/docs/guides/read-file/arraybuffer.mdx +30 -0
  123. package/docs/guides/read-file/buffer.mdx +21 -0
  124. package/docs/guides/read-file/exists.mdx +18 -0
  125. package/docs/guides/read-file/json.mdx +19 -0
  126. package/docs/guides/read-file/mime.mdx +22 -0
  127. package/docs/guides/read-file/stream.mdx +28 -0
  128. package/docs/guides/read-file/string.mdx +24 -0
  129. package/docs/guides/read-file/uint8array.mdx +23 -0
  130. package/docs/guides/read-file/watch.mdx +66 -0
  131. package/docs/guides/runtime/build-time-constants.mdx +295 -0
  132. package/docs/guides/runtime/cicd.mdx +45 -0
  133. package/docs/guides/runtime/codesign-macos-executable.mdx +61 -0
  134. package/docs/guides/runtime/define-constant.mdx +149 -0
  135. package/docs/guides/runtime/delete-directory.mdx +39 -0
  136. package/docs/guides/runtime/delete-file.mdx +21 -0
  137. package/docs/guides/runtime/heap-snapshot.mdx +28 -0
  138. package/docs/guides/runtime/import-html.mdx +15 -0
  139. package/docs/guides/runtime/import-json.mdx +46 -0
  140. package/docs/guides/runtime/import-json5.mdx +74 -0
  141. package/docs/guides/runtime/import-toml.mdx +32 -0
  142. package/docs/guides/runtime/import-yaml.mdx +104 -0
  143. package/docs/guides/runtime/read-env.mdx +37 -0
  144. package/docs/guides/runtime/set-env.mdx +51 -0
  145. package/docs/guides/runtime/shell.mdx +42 -0
  146. package/docs/guides/runtime/timezone.mdx +38 -0
  147. package/docs/guides/runtime/tsconfig-paths.mdx +31 -0
  148. package/docs/guides/runtime/typescript.mdx +51 -0
  149. package/docs/guides/runtime/vscode-debugger.mdx +47 -0
  150. package/docs/guides/runtime/web-debugger.mdx +103 -0
  151. package/docs/guides/streams/node-readable-to-arraybuffer.mdx +13 -0
  152. package/docs/guides/streams/node-readable-to-blob.mdx +13 -0
  153. package/docs/guides/streams/node-readable-to-json.mdx +14 -0
  154. package/docs/guides/streams/node-readable-to-string.mdx +14 -0
  155. package/docs/guides/streams/node-readable-to-uint8array.mdx +13 -0
  156. package/docs/guides/streams/to-array.mdx +16 -0
  157. package/docs/guides/streams/to-arraybuffer.mdx +16 -0
  158. package/docs/guides/streams/to-blob.mdx +16 -0
  159. package/docs/guides/streams/to-buffer.mdx +17 -0
  160. package/docs/guides/streams/to-json.mdx +16 -0
  161. package/docs/guides/streams/to-string.mdx +16 -0
  162. package/docs/guides/streams/to-typedarray.mdx +24 -0
  163. package/docs/guides/test/bail.mdx +24 -0
  164. package/docs/guides/test/concurrent-test-glob.mdx +146 -0
  165. package/docs/guides/test/coverage-threshold.mdx +67 -0
  166. package/docs/guides/test/coverage.mdx +49 -0
  167. package/docs/guides/test/happy-dom.mdx +73 -0
  168. package/docs/guides/test/migrate-from-jest.mdx +125 -0
  169. package/docs/guides/test/mock-clock.mdx +50 -0
  170. package/docs/guides/test/mock-functions.mdx +70 -0
  171. package/docs/guides/test/rerun-each.mdx +16 -0
  172. package/docs/guides/test/run-tests.mdx +116 -0
  173. package/docs/guides/test/skip-tests.mdx +43 -0
  174. package/docs/guides/test/snapshot.mdx +102 -0
  175. package/docs/guides/test/spy-on.mdx +49 -0
  176. package/docs/guides/test/svelte-test.mdx +113 -0
  177. package/docs/guides/test/testing-library.mdx +93 -0
  178. package/docs/guides/test/timeout.mdx +17 -0
  179. package/docs/guides/test/todo-tests.mdx +74 -0
  180. package/docs/guides/test/update-snapshots.mdx +49 -0
  181. package/docs/guides/test/watch-mode.mdx +24 -0
  182. package/docs/guides/util/base64.mdx +17 -0
  183. package/docs/guides/util/deep-equals.mdx +41 -0
  184. package/docs/guides/util/deflate.mdx +20 -0
  185. package/docs/guides/util/detect-bun.mdx +28 -0
  186. package/docs/guides/util/entrypoint.mdx +19 -0
  187. package/docs/guides/util/escape-html.mdx +24 -0
  188. package/docs/guides/util/file-url-to-path.mdx +16 -0
  189. package/docs/guides/util/gzip.mdx +20 -0
  190. package/docs/guides/util/hash-a-password.mdx +56 -0
  191. package/docs/guides/util/import-meta-dir.mdx +15 -0
  192. package/docs/guides/util/import-meta-file.mdx +15 -0
  193. package/docs/guides/util/import-meta-path.mdx +15 -0
  194. package/docs/guides/util/javascript-uuid.mdx +25 -0
  195. package/docs/guides/util/main.mdx +43 -0
  196. package/docs/guides/util/path-to-file-url.mdx +16 -0
  197. package/docs/guides/util/sleep.mdx +24 -0
  198. package/docs/guides/util/upgrade.mdx +93 -0
  199. package/docs/guides/util/version.mdx +23 -0
  200. package/docs/guides/util/which-path-to-executable-bin.mdx +17 -0
  201. package/docs/guides/websocket/compression.mdx +33 -0
  202. package/docs/guides/websocket/context.mdx +79 -0
  203. package/docs/guides/websocket/pubsub.mdx +43 -0
  204. package/docs/guides/websocket/simple.mdx +38 -0
  205. package/docs/guides/write-file/append.mdx +54 -0
  206. package/docs/guides/write-file/basic.mdx +46 -0
  207. package/docs/guides/write-file/blob.mdx +30 -0
  208. package/docs/guides/write-file/cat.mdx +19 -0
  209. package/docs/guides/write-file/file-cp.mdx +18 -0
  210. package/docs/guides/write-file/filesink.mdx +54 -0
  211. package/docs/guides/write-file/response.mdx +19 -0
  212. package/docs/guides/write-file/stdout.mdx +23 -0
  213. package/docs/guides/write-file/stream.mdx +19 -0
  214. package/docs/guides/write-file/unlink.mdx +18 -0
  215. package/docs/index.mdx +133 -0
  216. package/docs/installation.mdx +372 -0
  217. package/docs/pm/bunx.mdx +91 -0
  218. package/docs/pm/catalogs.mdx +292 -0
  219. package/docs/pm/cli/add.mdx +179 -0
  220. package/docs/pm/cli/audit.mdx +60 -0
  221. package/docs/pm/cli/info.mdx +70 -0
  222. package/docs/pm/cli/install.mdx +591 -0
  223. package/docs/pm/cli/link.mdx +61 -0
  224. package/docs/pm/cli/outdated.mdx +197 -0
  225. package/docs/pm/cli/patch.mdx +69 -0
  226. package/docs/pm/cli/pm.mdx +323 -0
  227. package/docs/pm/cli/publish.mdx +131 -0
  228. package/docs/pm/cli/remove.mdx +16 -0
  229. package/docs/pm/cli/update.mdx +140 -0
  230. package/docs/pm/cli/why.mdx +84 -0
  231. package/docs/pm/filter.mdx +127 -0
  232. package/docs/pm/global-cache.mdx +72 -0
  233. package/docs/pm/isolated-installs.mdx +220 -0
  234. package/docs/pm/lifecycle.mdx +64 -0
  235. package/docs/pm/lockfile.mdx +64 -0
  236. package/docs/pm/npmrc.mdx +245 -0
  237. package/docs/pm/overrides.mdx +83 -0
  238. package/docs/pm/scopes-registries.mdx +35 -0
  239. package/docs/pm/security-scanner-api.mdx +95 -0
  240. package/docs/pm/workspaces.mdx +115 -0
  241. package/docs/project/benchmarking.mdx +296 -0
  242. package/docs/project/bindgen.mdx +223 -0
  243. package/docs/project/building-windows.mdx +143 -0
  244. package/docs/project/contributing.mdx +366 -0
  245. package/docs/project/feedback.mdx +20 -0
  246. package/docs/project/license.mdx +78 -0
  247. package/docs/project/roadmap.mdx +8 -0
  248. package/docs/quickstart.mdx +251 -0
  249. package/docs/runtime/archive.mdx +452 -0
  250. package/docs/runtime/auto-install.mdx +97 -0
  251. package/docs/runtime/binary-data.mdx +846 -0
  252. package/docs/runtime/bun-apis.mdx +60 -0
  253. package/docs/runtime/bunfig.mdx +765 -0
  254. package/docs/runtime/c-compiler.mdx +204 -0
  255. package/docs/runtime/child-process.mdx +659 -0
  256. package/docs/runtime/color.mdx +267 -0
  257. package/docs/runtime/console.mdx +67 -0
  258. package/docs/runtime/cookies.mdx +454 -0
  259. package/docs/runtime/cron.mdx +358 -0
  260. package/docs/runtime/csrf.mdx +171 -0
  261. package/docs/runtime/debugger.mdx +335 -0
  262. package/docs/runtime/environment-variables.mdx +231 -0
  263. package/docs/runtime/ffi.mdx +567 -0
  264. package/docs/runtime/file-io.mdx +306 -0
  265. package/docs/runtime/file-system-router.mdx +118 -0
  266. package/docs/runtime/file-types.mdx +482 -0
  267. package/docs/runtime/glob.mdx +181 -0
  268. package/docs/runtime/globals.mdx +72 -0
  269. package/docs/runtime/hashing.mdx +315 -0
  270. package/docs/runtime/html-rewriter.mdx +333 -0
  271. package/docs/runtime/http/cookies.mdx +79 -0
  272. package/docs/runtime/http/error-handling.mdx +40 -0
  273. package/docs/runtime/http/metrics.mdx +36 -0
  274. package/docs/runtime/http/routing.mdx +289 -0
  275. package/docs/runtime/http/server.mdx +672 -0
  276. package/docs/runtime/http/tls.mdx +101 -0
  277. package/docs/runtime/http/websockets.mdx +414 -0
  278. package/docs/runtime/index.mdx +223 -0
  279. package/docs/runtime/json5.mdx +271 -0
  280. package/docs/runtime/jsonl.mdx +188 -0
  281. package/docs/runtime/jsx.mdx +115 -0
  282. package/docs/runtime/markdown.mdx +381 -0
  283. package/docs/runtime/module-resolution.mdx +374 -0
  284. package/docs/runtime/networking/dns.mdx +111 -0
  285. package/docs/runtime/networking/fetch.mdx +484 -0
  286. package/docs/runtime/networking/tcp.mdx +239 -0
  287. package/docs/runtime/networking/udp.mdx +180 -0
  288. package/docs/runtime/node-api.mdx +19 -0
  289. package/docs/runtime/nodejs-compat.mdx +468 -0
  290. package/docs/runtime/plugins.mdx +419 -0
  291. package/docs/runtime/redis.mdx +583 -0
  292. package/docs/runtime/repl.mdx +176 -0
  293. package/docs/runtime/s3.mdx +881 -0
  294. package/docs/runtime/secrets.mdx +340 -0
  295. package/docs/runtime/semver.mdx +57 -0
  296. package/docs/runtime/shell.mdx +637 -0
  297. package/docs/runtime/sql.mdx +1404 -0
  298. package/docs/runtime/sqlite.mdx +721 -0
  299. package/docs/runtime/streams.mdx +232 -0
  300. package/docs/runtime/templating/create.mdx +269 -0
  301. package/docs/runtime/templating/init.mdx +58 -0
  302. package/docs/runtime/toml.mdx +238 -0
  303. package/docs/runtime/transpiler.mdx +288 -0
  304. package/docs/runtime/typescript.mdx +58 -0
  305. package/docs/runtime/utils.mdx +1010 -0
  306. package/docs/runtime/watch-mode.mdx +161 -0
  307. package/docs/runtime/web-apis.mdx +29 -0
  308. package/docs/runtime/workers.mdx +314 -0
  309. package/docs/runtime/yaml.mdx +470 -0
  310. package/docs/snippets/cli/add.mdx +166 -0
  311. package/docs/snippets/cli/build.mdx +197 -0
  312. package/docs/snippets/cli/bunx.mdx +49 -0
  313. package/docs/snippets/cli/feedback.mdx +17 -0
  314. package/docs/snippets/cli/init.mdx +84 -0
  315. package/docs/snippets/cli/install.mdx +173 -0
  316. package/docs/snippets/cli/link.mdx +163 -0
  317. package/docs/snippets/cli/outdated.mdx +140 -0
  318. package/docs/snippets/cli/patch.mdx +171 -0
  319. package/docs/snippets/cli/publish.mdx +198 -0
  320. package/docs/snippets/cli/remove.mdx +146 -0
  321. package/docs/snippets/cli/run.mdx +305 -0
  322. package/docs/snippets/cli/test.mdx +105 -0
  323. package/docs/snippets/cli/update.mdx +144 -0
  324. package/docs/test/code-coverage.mdx +409 -0
  325. package/docs/test/configuration.mdx +574 -0
  326. package/docs/test/dates-times.mdx +129 -0
  327. package/docs/test/discovery.mdx +90 -0
  328. package/docs/test/dom.mdx +226 -0
  329. package/docs/test/index.mdx +409 -0
  330. package/docs/test/lifecycle.mdx +366 -0
  331. package/docs/test/mocks.mdx +637 -0
  332. package/docs/test/reporters.mdx +126 -0
  333. package/docs/test/runtime-behavior.mdx +342 -0
  334. package/docs/test/snapshots.mdx +434 -0
  335. package/docs/test/writing-tests.mdx +672 -0
  336. package/docs/typescript.mdx +54 -0
  337. package/extensions.d.ts +40 -0
  338. package/fetch.d.ts +79 -0
  339. package/ffi.d.ts +1154 -0
  340. package/globals.d.ts +2067 -0
  341. package/html-rewriter.d.ts +186 -0
  342. package/index.d.ts +32 -0
  343. package/jsc.d.ts +233 -0
  344. package/jsx.d.ts +11 -0
  345. package/overrides.d.ts +376 -0
  346. package/package.json +53 -0
  347. package/redis.d.ts +3352 -0
  348. package/s3.d.ts +1354 -0
  349. package/security.d.ts +101 -0
  350. package/serve.d.ts +1296 -0
  351. package/shell.d.ts +380 -0
  352. package/sql.d.ts +887 -0
  353. package/sqlite.d.ts +1322 -0
  354. package/test-globals.d.ts +22 -0
  355. package/test.d.ts +2392 -0
  356. package/vendor/expect-type/branding.d.ts +283 -0
  357. package/vendor/expect-type/index.d.ts +1207 -0
  358. package/vendor/expect-type/messages.d.ts +395 -0
  359. package/vendor/expect-type/overloads.d.ts +669 -0
  360. package/vendor/expect-type/utils.d.ts +431 -0
  361. package/wasm.d.ts +193 -0
package/s3.d.ts ADDED
@@ -0,0 +1,1354 @@
1
+ declare module "bun" {
2
+ /**
3
+ * Fast incremental writer for files and pipes.
4
+ *
5
+ * This uses the same interface as {@link ArrayBufferSink}, but writes to a file or pipe.
6
+ */
7
+ interface FileSink {
8
+ /**
9
+ * Write a chunk of data to the file.
10
+ *
11
+ * If the file descriptor is not writable yet, the data is buffered.
12
+ *
13
+ * @param chunk The data to write
14
+ * @returns Number of bytes written or, if the write is pending, a Promise resolving to the number of bytes
15
+ */
16
+ write(chunk: string | ArrayBufferView | ArrayBuffer | SharedArrayBuffer): number | Promise<number>;
17
+ /**
18
+ * Flush the internal buffer, committing the data to disk or the pipe.
19
+ *
20
+ * @returns Number of bytes flushed or a Promise resolving to the number of bytes
21
+ */
22
+ flush(): number | Promise<number>;
23
+ /**
24
+ * Close the file descriptor. This also flushes the internal buffer.
25
+ *
26
+ * @param error Optional error to associate with the close operation
27
+ * @returns Number of bytes written or a Promise resolving to the number of bytes
28
+ */
29
+ end(error?: Error): number | Promise<number>;
30
+
31
+ /**
32
+ * Start the file sink with provided options.
33
+ *
34
+ * @param options Configuration options for the file sink
35
+ */
36
+ start(options?: {
37
+ /**
38
+ * Preallocate an internal buffer of this size
39
+ * This can significantly improve performance when the chunk size is small
40
+ */
41
+ highWaterMark?: number;
42
+ }): void;
43
+
44
+ /**
45
+ * For FIFOs & pipes, this lets you decide whether Bun's process should
46
+ * remain alive until the pipe is closed.
47
+ *
48
+ * By default, it is automatically managed. While the stream is open, the
49
+ * process remains alive and once the other end hangs up or the stream
50
+ * closes, the process exits.
51
+ *
52
+ * If you previously called {@link unref}, you can call this again to re-enable automatic management.
53
+ *
54
+ * Internally, it will reference count the number of times this is called. By default, that number is 1
55
+ *
56
+ * If the file is not a FIFO or pipe, {@link ref} and {@link unref} do
57
+ * nothing. If the pipe is already closed, this does nothing.
58
+ */
59
+ ref(): void;
60
+
61
+ /**
62
+ * For FIFOs & pipes, this lets you decide whether Bun's process should
63
+ * remain alive until the pipe is closed.
64
+ *
65
+ * If you want to allow Bun's process to terminate while the stream is open,
66
+ * call this.
67
+ *
68
+ * If the file is not a FIFO or pipe, {@link ref} and {@link unref} do
69
+ * nothing. If the pipe is already closed, this does nothing.
70
+ */
71
+ unref(): void;
72
+ }
73
+
74
+ interface NetworkSink extends FileSink {
75
+ /**
76
+ * Write a chunk of data to the network.
77
+ *
78
+ * If the network is not writable yet, the data is buffered.
79
+ *
80
+ * @param chunk The data to write
81
+ * @returns Number of bytes written or, if the write is pending, a Promise resolving to the number of bytes
82
+ */
83
+ write(chunk: string | ArrayBufferView | ArrayBuffer | SharedArrayBuffer): number | Promise<number>;
84
+ /**
85
+ * Flush the internal buffer, committing the data to the network.
86
+ *
87
+ * @returns Number of bytes flushed or a Promise resolving to the number of bytes
88
+ */
89
+ flush(): number | Promise<number>;
90
+ /**
91
+ * Finish the upload. This also flushes the internal buffer.
92
+ *
93
+ * @param error Optional error to associate with the end operation
94
+ * @returns Number of bytes written or a Promise resolving to the number of bytes
95
+ */
96
+ end(error?: Error): number | Promise<number>;
97
+
98
+ /**
99
+ * Get the stat of the file.
100
+ *
101
+ * @returns Promise resolving to the file stats
102
+ */
103
+ stat(): Promise<import("node:fs").Stats>;
104
+ }
105
+
106
+ /**
107
+ * Configuration options for S3 operations
108
+ */
109
+ interface S3Options extends BlobPropertyBag {
110
+ /**
111
+ * The Access Control List (ACL) policy for the file.
112
+ * Controls who can access the file and what permissions they have.
113
+ *
114
+ * @example
115
+ * // Setting public read access
116
+ * const file = s3.file("public-file.txt", {
117
+ * acl: "public-read",
118
+ * bucket: "my-bucket"
119
+ * });
120
+ *
121
+ * @example
122
+ * // Using with presigned URLs
123
+ * const url = file.presign({
124
+ * acl: "public-read",
125
+ * expiresIn: 3600
126
+ * });
127
+ */
128
+ acl?:
129
+ | "private"
130
+ | "public-read"
131
+ | "public-read-write"
132
+ | "aws-exec-read"
133
+ | "authenticated-read"
134
+ | "bucket-owner-read"
135
+ | "bucket-owner-full-control"
136
+ | "log-delivery-write";
137
+
138
+ /**
139
+ * The S3 bucket name. Defaults to `S3_BUCKET` or `AWS_BUCKET` environment variables.
140
+ *
141
+ * @example
142
+ * // Using explicit bucket
143
+ * const file = s3.file("my-file.txt", { bucket: "my-bucket" });
144
+ *
145
+ * @example
146
+ * // Using environment variables
147
+ * // With S3_BUCKET=my-bucket in .env
148
+ * const file = s3.file("my-file.txt");
149
+ */
150
+ bucket?: string;
151
+
152
+ /**
153
+ * The AWS region. Defaults to `S3_REGION` or `AWS_REGION` environment variables.
154
+ *
155
+ * @example
156
+ * const file = s3.file("my-file.txt", {
157
+ * bucket: "my-bucket",
158
+ * region: "us-west-2"
159
+ * });
160
+ */
161
+ region?: string;
162
+
163
+ /**
164
+ * The access key ID for authentication.
165
+ * Defaults to `S3_ACCESS_KEY_ID` or `AWS_ACCESS_KEY_ID` environment variables.
166
+ */
167
+ accessKeyId?: string;
168
+
169
+ /**
170
+ * The secret access key for authentication.
171
+ * Defaults to `S3_SECRET_ACCESS_KEY` or `AWS_SECRET_ACCESS_KEY` environment variables.
172
+ */
173
+ secretAccessKey?: string;
174
+
175
+ /**
176
+ * Optional session token for temporary credentials.
177
+ * Defaults to `S3_SESSION_TOKEN` or `AWS_SESSION_TOKEN` environment variables.
178
+ *
179
+ * @example
180
+ * // Using temporary credentials
181
+ * const file = s3.file("my-file.txt", {
182
+ * accessKeyId: tempAccessKey,
183
+ * secretAccessKey: tempSecretKey,
184
+ * sessionToken: tempSessionToken
185
+ * });
186
+ */
187
+ sessionToken?: string;
188
+
189
+ /**
190
+ * The S3-compatible service endpoint URL.
191
+ * Defaults to `S3_ENDPOINT` or `AWS_ENDPOINT` environment variables.
192
+ *
193
+ * @example
194
+ * // AWS S3
195
+ * const file = s3.file("my-file.txt", {
196
+ * endpoint: "https://s3.us-east-1.amazonaws.com"
197
+ * });
198
+ *
199
+ * @example
200
+ * // Cloudflare R2
201
+ * const file = s3.file("my-file.txt", {
202
+ * endpoint: "https://<account-id>.r2.cloudflarestorage.com"
203
+ * });
204
+ *
205
+ * @example
206
+ * // DigitalOcean Spaces
207
+ * const file = s3.file("my-file.txt", {
208
+ * endpoint: "https://<region>.digitaloceanspaces.com"
209
+ * });
210
+ *
211
+ * @example
212
+ * // MinIO (local development)
213
+ * const file = s3.file("my-file.txt", {
214
+ * endpoint: "http://localhost:9000"
215
+ * });
216
+ */
217
+ endpoint?: string;
218
+
219
+ /**
220
+ * Use virtual hosted style endpoint. default to false, when true if `endpoint` is informed it will ignore the `bucket`
221
+ *
222
+ * @example
223
+ * // Using virtual hosted style
224
+ * const file = s3.file("my-file.txt", {
225
+ * virtualHostedStyle: true,
226
+ * endpoint: "https://my-bucket.s3.us-east-1.amazonaws.com"
227
+ * });
228
+ */
229
+ virtualHostedStyle?: boolean;
230
+
231
+ /**
232
+ * The size of each part in multipart uploads (in bytes).
233
+ * - Minimum: 5 MiB
234
+ * - Maximum: 5120 MiB
235
+ * - Default: 5 MiB
236
+ *
237
+ * @example
238
+ * // Configuring multipart uploads
239
+ * const file = s3.file("large-file.dat", {
240
+ * partSize: 10 * 1024 * 1024, // 10 MiB parts
241
+ * queueSize: 4 // Upload 4 parts in parallel
242
+ * });
243
+ *
244
+ * const writer = file.writer();
245
+ * // ... write large file in chunks
246
+ */
247
+ partSize?: number;
248
+
249
+ /**
250
+ * Number of parts to upload in parallel for multipart uploads.
251
+ * - Default: 5
252
+ * - Maximum: 255
253
+ *
254
+ * Increasing this value can improve upload speeds for large files
255
+ * but will use more memory.
256
+ */
257
+ queueSize?: number;
258
+
259
+ /**
260
+ * Number of retry attempts for failed uploads.
261
+ * - Default: 3
262
+ * - Maximum: 255
263
+ *
264
+ * @example
265
+ * // Setting retry attempts
266
+ * const file = s3.file("my-file.txt", {
267
+ * retry: 5 // Retry failed uploads up to 5 times
268
+ * });
269
+ */
270
+ retry?: number;
271
+
272
+ /**
273
+ * The Content-Type of the file.
274
+ * Automatically set based on file extension when possible.
275
+ *
276
+ * @example
277
+ * // Setting explicit content type
278
+ * const file = s3.file("data.bin", {
279
+ * type: "application/octet-stream"
280
+ * });
281
+ */
282
+ type?: string;
283
+
284
+ /**
285
+ * The Content-Disposition header value.
286
+ * Controls how the file is presented when downloaded.
287
+ *
288
+ * @example
289
+ * // Setting attachment disposition with filename
290
+ * const file = s3.file("report.pdf", {
291
+ * contentDisposition: "attachment; filename=\"quarterly-report.pdf\""
292
+ * });
293
+ *
294
+ * @example
295
+ * // Setting inline disposition
296
+ * await s3.write("image.png", imageData, {
297
+ * contentDisposition: "inline"
298
+ * });
299
+ */
300
+ contentDisposition?: string | undefined;
301
+
302
+ /**
303
+ * The Content-Encoding header value.
304
+ * Specifies what content encodings have been applied to the object,
305
+ * for example to indicate that it has been compressed.
306
+ *
307
+ * @example
308
+ * // Setting gzip encoding
309
+ * const file = s3.file("data.json.gz", {
310
+ * contentEncoding: "gzip"
311
+ * });
312
+ *
313
+ * @example
314
+ * // Setting encoding when writing
315
+ * await s3.write("data.json.gz", compressedData, {
316
+ * contentEncoding: "gzip"
317
+ * });
318
+ */
319
+ contentEncoding?: string | undefined;
320
+
321
+ /**
322
+ * By default, Amazon S3 uses the STANDARD Storage Class to store newly created objects.
323
+ *
324
+ * @example
325
+ * // Setting explicit Storage class
326
+ * const file = s3.file("my-file.json", {
327
+ * storageClass: "STANDARD_IA"
328
+ * });
329
+ */
330
+ storageClass?:
331
+ | "STANDARD"
332
+ | "DEEP_ARCHIVE"
333
+ | "EXPRESS_ONEZONE"
334
+ | "GLACIER"
335
+ | "GLACIER_IR"
336
+ | "INTELLIGENT_TIERING"
337
+ | "ONEZONE_IA"
338
+ | "OUTPOSTS"
339
+ | "REDUCED_REDUNDANCY"
340
+ | "SNOW"
341
+ | "STANDARD_IA";
342
+
343
+ /**
344
+ * When set to `true`, confirms that the requester knows they will be charged
345
+ * for the request and data transfer costs. Required for accessing objects
346
+ * in Requester Pays buckets.
347
+ *
348
+ * @see https://docs.aws.amazon.com/AmazonS3/latest/userguide/RequesterPaysBuckets.html
349
+ *
350
+ * @example
351
+ * // Accessing a file in a Requester Pays bucket
352
+ * const file = s3.file("data.csv", {
353
+ * bucket: "requester-pays-bucket",
354
+ * requestPayer: true
355
+ * });
356
+ * const content = await file.text();
357
+ *
358
+ * @example
359
+ * // Uploading to a Requester Pays bucket
360
+ * await s3.write("output.json", data, {
361
+ * bucket: "requester-pays-bucket",
362
+ * requestPayer: true
363
+ * });
364
+ */
365
+ requestPayer?: boolean;
366
+
367
+ /**
368
+ * @deprecated The size of the internal buffer in bytes. Defaults to 5 MiB. use `partSize` and `queueSize` instead.
369
+ */
370
+ highWaterMark?: number;
371
+ }
372
+
373
+ /**
374
+ * Options for generating presigned URLs
375
+ */
376
+ interface S3FilePresignOptions extends S3Options {
377
+ /**
378
+ * Number of seconds until the presigned URL expires.
379
+ * - Default: 86400 (1 day)
380
+ *
381
+ * @example
382
+ * // Short-lived URL
383
+ * const url = file.presign({
384
+ * expiresIn: 3600 // 1 hour
385
+ * });
386
+ *
387
+ * @example
388
+ * // Long-lived public URL
389
+ * const url = file.presign({
390
+ * expiresIn: 7 * 24 * 60 * 60, // 7 days
391
+ * acl: "public-read"
392
+ * });
393
+ */
394
+ expiresIn?: number;
395
+
396
+ /**
397
+ * The HTTP method allowed for the presigned URL.
398
+ *
399
+ * @example
400
+ * // GET URL for downloads
401
+ * const downloadUrl = file.presign({
402
+ * method: "GET",
403
+ * expiresIn: 3600
404
+ * });
405
+ *
406
+ * @example
407
+ * // PUT URL for uploads
408
+ * const uploadUrl = file.presign({
409
+ * method: "PUT",
410
+ * expiresIn: 3600,
411
+ * type: "application/json"
412
+ * });
413
+ */
414
+ method?: "GET" | "POST" | "PUT" | "DELETE" | "HEAD";
415
+ }
416
+
417
+ interface S3Stats {
418
+ size: number;
419
+ lastModified: Date;
420
+ etag: string;
421
+ type: string;
422
+ }
423
+
424
+ /**
425
+ * Represents a file in an S3-compatible storage service.
426
+ * Extends the Blob interface for compatibility with web APIs.
427
+ *
428
+ * @category Cloud Storage
429
+ */
430
+ interface S3File extends Blob {
431
+ /**
432
+ * The size of the file in bytes.
433
+ * This is a Promise because it requires a network request to determine the size.
434
+ *
435
+ * @example
436
+ * // Getting file size
437
+ * const size = await file.size;
438
+ * console.log(`File size: ${size} bytes`);
439
+ *
440
+ * @example
441
+ * // Check if file is larger than 1MB
442
+ * if (await file.size > 1024 * 1024) {
443
+ * console.log("Large file detected");
444
+ * }
445
+ */
446
+ /**
447
+ * TODO: figure out how to get the typescript types to not error for this property.
448
+ */
449
+ // size: Promise<number>;
450
+
451
+ /**
452
+ * Creates a new S3File representing a slice of the original file.
453
+ * Uses HTTP Range headers for efficient partial downloads.
454
+ *
455
+ * @param begin - Starting byte offset
456
+ * @param end - Ending byte offset (exclusive)
457
+ * @param contentType - Optional MIME type for the slice
458
+ * @returns A new S3File representing the specified range
459
+ *
460
+ * @example
461
+ * // Reading file header
462
+ * const header = file.slice(0, 1024);
463
+ * const headerText = await header.text();
464
+ *
465
+ * @example
466
+ * // Reading with content type
467
+ * const jsonSlice = file.slice(1024, 2048, "application/json");
468
+ * const data = await jsonSlice.json();
469
+ *
470
+ * @example
471
+ * // Reading from offset to end
472
+ * const remainder = file.slice(1024);
473
+ * const content = await remainder.text();
474
+ */
475
+ slice(begin?: number, end?: number, contentType?: string): S3File;
476
+ slice(begin?: number, contentType?: string): S3File;
477
+ slice(contentType?: string): S3File;
478
+
479
+ /**
480
+ * Creates a writable stream for uploading data.
481
+ * Suitable for large files as it uses multipart upload.
482
+ *
483
+ * @param options - Configuration for the upload
484
+ * @returns A NetworkSink for writing data
485
+ *
486
+ * @example
487
+ * // Basic streaming write
488
+ * const writer = file.writer({
489
+ * type: "application/json"
490
+ * });
491
+ * writer.write('{"hello": ');
492
+ * writer.write('"world"}');
493
+ * await writer.end();
494
+ *
495
+ * @example
496
+ * // Optimized large file upload
497
+ * const writer = file.writer({
498
+ * partSize: 10 * 1024 * 1024, // 10MB parts
499
+ * queueSize: 4, // Upload 4 parts in parallel
500
+ * retry: 3 // Retry failed parts
501
+ * });
502
+ *
503
+ * // Write large chunks of data efficiently
504
+ * for (const chunk of largeDataChunks) {
505
+ * writer.write(chunk);
506
+ * }
507
+ * await writer.end();
508
+ *
509
+ * @example
510
+ * // Error handling
511
+ * const writer = file.writer();
512
+ * try {
513
+ * writer.write(data);
514
+ * await writer.end();
515
+ * } catch (err) {
516
+ * console.error('Upload failed:', err);
517
+ * // Writer will automatically abort multipart upload on error
518
+ * }
519
+ */
520
+ writer(options?: S3Options): NetworkSink;
521
+
522
+ /**
523
+ * Gets a readable stream of the file's content.
524
+ * Useful for processing large files without loading them entirely into memory.
525
+ *
526
+ * @returns A ReadableStream for the file content
527
+ *
528
+ * @example
529
+ * // Basic streaming read
530
+ * const stream = file.stream();
531
+ * for await (const chunk of stream) {
532
+ * console.log('Received chunk:', chunk);
533
+ * }
534
+ *
535
+ * @example
536
+ * // Piping to response
537
+ * const stream = file.stream();
538
+ * return new Response(stream, {
539
+ * headers: { 'Content-Type': file.type }
540
+ * });
541
+ *
542
+ * @example
543
+ * // Processing large files
544
+ * const stream = file.stream();
545
+ * const textDecoder = new TextDecoder();
546
+ * for await (const chunk of stream) {
547
+ * const text = textDecoder.decode(chunk);
548
+ * // Process text chunk by chunk
549
+ * }
550
+ */
551
+ readonly readable: ReadableStream<Uint8Array<ArrayBuffer>>;
552
+ stream(): ReadableStream<Uint8Array<ArrayBuffer>>;
553
+
554
+ /**
555
+ * The name or path of the file in the bucket.
556
+ *
557
+ * @example
558
+ * const file = s3.file("folder/image.jpg");
559
+ * console.log(file.name); // "folder/image.jpg"
560
+ */
561
+ readonly name?: string;
562
+
563
+ /**
564
+ * The bucket name containing the file.
565
+ *
566
+ * @example
567
+ * const file = s3.file("s3://my-bucket/file.txt");
568
+ * console.log(file.bucket); // "my-bucket"
569
+ */
570
+ readonly bucket?: string;
571
+
572
+ /**
573
+ * Checks if the file exists in S3.
574
+ * Uses HTTP HEAD request to efficiently check existence without downloading.
575
+ *
576
+ * @returns Promise resolving to true if file exists, false otherwise
577
+ *
578
+ * @example
579
+ * // Basic existence check
580
+ * if (await file.exists()) {
581
+ * console.log("File exists in S3");
582
+ * }
583
+ *
584
+ * @example
585
+ * // With error handling
586
+ * try {
587
+ * const exists = await file.exists();
588
+ * if (!exists) {
589
+ * console.log("File not found");
590
+ * }
591
+ * } catch (err) {
592
+ * console.error("Error checking file:", err);
593
+ * }
594
+ */
595
+ exists(): Promise<boolean>;
596
+
597
+ /**
598
+ * Uploads data to S3.
599
+ * Supports various input types and automatically handles large files.
600
+ *
601
+ * @param data - The data to upload
602
+ * @param options - Upload configuration options
603
+ * @returns Promise resolving to number of bytes written
604
+ *
605
+ * @example
606
+ * // Writing string data
607
+ * await file.write("Hello World", {
608
+ * type: "text/plain"
609
+ * });
610
+ *
611
+ * @example
612
+ * // Writing JSON
613
+ * const data = { hello: "world" };
614
+ * await file.write(JSON.stringify(data), {
615
+ * type: "application/json"
616
+ * });
617
+ *
618
+ * @example
619
+ * // Writing from Response
620
+ * const response = await fetch("https://example.com/data");
621
+ * await file.write(response);
622
+ *
623
+ * @example
624
+ * // Writing with ACL
625
+ * await file.write(data, {
626
+ * acl: "public-read",
627
+ * type: "application/octet-stream"
628
+ * });
629
+ */
630
+ write(
631
+ data:
632
+ | string
633
+ | ArrayBufferView
634
+ | ArrayBuffer
635
+ | SharedArrayBuffer
636
+ | Request
637
+ | Response
638
+ | BunFile
639
+ | S3File
640
+ | Blob
641
+ | Archive,
642
+ options?: S3Options,
643
+ ): Promise<number>;
644
+
645
+ /**
646
+ * Generates a presigned URL for the file.
647
+ * Allows temporary access to the file without exposing credentials.
648
+ *
649
+ * @param options - Configuration for the presigned URL
650
+ * @returns Presigned URL string
651
+ *
652
+ * @example
653
+ * // Basic download URL
654
+ * const url = file.presign({
655
+ * expiresIn: 3600 // 1 hour
656
+ * });
657
+ *
658
+ * @example
659
+ * // Upload URL with specific content type
660
+ * const uploadUrl = file.presign({
661
+ * method: "PUT",
662
+ * expiresIn: 3600,
663
+ * type: "image/jpeg",
664
+ * acl: "public-read"
665
+ * });
666
+ *
667
+ * @example
668
+ * // URL with custom permissions
669
+ * const url = file.presign({
670
+ * method: "GET",
671
+ * expiresIn: 7 * 24 * 60 * 60, // 7 days
672
+ * acl: "public-read"
673
+ * });
674
+ */
675
+ presign(options?: S3FilePresignOptions): string;
676
+
677
+ /**
678
+ * Deletes the file from S3.
679
+ *
680
+ * @returns Promise that resolves when deletion is complete
681
+ *
682
+ * @example
683
+ * // Basic deletion
684
+ * await file.delete();
685
+ *
686
+ * @example
687
+ * // With error handling
688
+ * try {
689
+ * await file.delete();
690
+ * console.log("File deleted successfully");
691
+ * } catch (err) {
692
+ * console.error("Failed to delete file:", err);
693
+ * }
694
+ */
695
+ delete(): Promise<void>;
696
+
697
+ /**
698
+ * Alias for delete() method.
699
+ * Provided for compatibility with Node.js fs API naming.
700
+ *
701
+ * @example
702
+ * await file.unlink();
703
+ */
704
+ unlink: S3File["delete"];
705
+
706
+ /**
707
+ * Get the stat of a file in an S3-compatible storage service.
708
+ *
709
+ * @returns Promise resolving to S3Stat
710
+ */
711
+ stat(): Promise<S3Stats>;
712
+ }
713
+
714
+ interface S3ListObjectsOptions {
715
+ /** Limits the response to keys that begin with the specified prefix. */
716
+ prefix?: string;
717
+ /** ContinuationToken indicates to S3 that the list is being continued on this bucket with a token. ContinuationToken is obfuscated and is not a real key. You can use this ContinuationToken for pagination of the list results. */
718
+ continuationToken?: string;
719
+ /** A delimiter is a character that you use to group keys. */
720
+ delimiter?: string;
721
+ /** Sets the maximum number of keys returned in the response. By default, the action returns up to 1,000 key names. The response might contain fewer keys but will never contain more. */
722
+ maxKeys?: number;
723
+ /** StartAfter is where you want S3 to start listing from. S3 starts listing after this specified key. StartAfter can be any key in the bucket. */
724
+ startAfter?: string;
725
+ /** Encoding type used by S3 to encode the object keys in the response. Responses are encoded only in UTF-8. An object key can contain any Unicode character. However, the XML 1.0 parser can't parse certain characters, such as characters with an ASCII value from 0 to 10. For characters that aren't supported in XML 1.0, you can add this parameter to request that S3 encode the keys in the response. */
726
+ encodingType?: "url";
727
+ /** If you want to return the owner field with each key in the result, then set the FetchOwner field to true. */
728
+ fetchOwner?: boolean;
729
+ }
730
+
731
+ interface S3ListObjectsResponse {
732
+ /** All of the keys (up to 1,000) that share the same prefix are grouped together. When counting the total numbers of returns by this API operation, this group of keys is considered as one item.
733
+ *
734
+ * A response can contain CommonPrefixes only if you specify a delimiter.
735
+ *
736
+ * CommonPrefixes contains all (if there are any) keys between Prefix and the next occurrence of the string specified by a delimiter.
737
+ *
738
+ * CommonPrefixes lists keys that act like subdirectories in the directory specified by Prefix.
739
+ *
740
+ * For example, if the prefix is notes/ and the delimiter is a slash (/) as in notes/summer/july, the common prefix is notes/summer/. All of the keys that roll up into a common prefix count as a single return when calculating the number of returns. */
741
+ commonPrefixes?: { prefix: string }[];
742
+ /** Metadata about each object returned. */
743
+ contents?: {
744
+ /** The algorithm that was used to create a checksum of the object. */
745
+ checksumAlgorithm?: "CRC32" | "CRC32C" | "SHA1" | "SHA256" | "CRC64NVME";
746
+ /** The checksum type that is used to calculate the object's checksum value. */
747
+ checksumType?: "COMPOSITE" | "FULL_OBJECT";
748
+ /**
749
+ * The entity tag is a hash of the object. The ETag reflects changes only to the contents of an object, not its metadata. The ETag may or may not be an MD5 digest of the object data. Whether or not it is depends on how the object was created and how it is encrypted as described below:
750
+ *
751
+ * - Objects created by the PUT Object, POST Object, or Copy operation, or through the AWS Management Console, and are encrypted by SSE-S3 or plaintext, have ETags that are an MD5 digest of their object data.
752
+ * - Objects created by the PUT Object, POST Object, or Copy operation, or through the AWS Management Console, and are encrypted by SSE-C or SSE-KMS, have ETags that are not an MD5 digest of their object data.
753
+ * - If an object is created by either the Multipart Upload or Part Copy operation, the ETag is not an MD5 digest, regardless of the method of encryption. If an object is larger than 16 MB, the AWS Management Console will upload or copy that object as a Multipart Upload, and therefore the ETag will not be an MD5 digest.
754
+ *
755
+ * MD5 is not supported by directory buckets.
756
+ */
757
+ eTag?: string;
758
+ /** The name that you assign to an object. You use the object key to retrieve the object. */
759
+ key: string;
760
+ /** Creation date of the object. */
761
+ lastModified?: string;
762
+ /** The owner of the object */
763
+ owner?: {
764
+ /** The ID of the owner. */
765
+ id?: string;
766
+ /** The display name of the owner. */
767
+ displayName?: string;
768
+ };
769
+ /** Specifies the restoration status of an object. Objects in certain storage classes must be restored before they can be retrieved. */
770
+ restoreStatus?: {
771
+ /** Specifies whether the object is currently being restored. */
772
+ isRestoreInProgress?: boolean;
773
+ /** Indicates when the restored copy will expire. This value is populated only if the object has already been restored. */
774
+ restoreExpiryDate?: string;
775
+ };
776
+ /** Size in bytes of the object */
777
+ size?: number;
778
+ /** The class of storage used to store the object. */
779
+ storageClass?:
780
+ | "STANDARD"
781
+ | "REDUCED_REDUNDANCY"
782
+ | "GLACIER"
783
+ | "STANDARD_IA"
784
+ | "ONEZONE_IA"
785
+ | "INTELLIGENT_TIERING"
786
+ | "DEEP_ARCHIVE"
787
+ | "OUTPOSTS"
788
+ | "GLACIER_IR"
789
+ | "SNOW"
790
+ | "EXPRESS_ONEZONE";
791
+ }[];
792
+ /** If ContinuationToken was sent with the request, it is included in the response. You can use the returned ContinuationToken for pagination of the list response. */
793
+ continuationToken?: string;
794
+ /** Causes keys that contain the same string between the prefix and the first occurrence of the delimiter to be rolled up into a single result element in the CommonPrefixes collection. These rolled-up keys are not returned elsewhere in the response. Each rolled-up result counts as only one return against the MaxKeys value. */
795
+ delimiter?: string;
796
+ /** Encoding type used by S3 to encode object key names in the XML response. */
797
+ encodingType?: "url";
798
+ /** Set to false if all of the results were returned. Set to true if more keys are available to return. If the number of results exceeds that specified by MaxKeys, all of the results might not be returned. */
799
+ isTruncated?: boolean;
800
+ /** KeyCount is the number of keys returned with this request. KeyCount will always be less than or equal to the MaxKeys field. For example, if you ask for 50 keys, your result will include 50 keys or fewer. */
801
+ keyCount?: number;
802
+ /** Sets the maximum number of keys returned in the response. By default, the action returns up to 1,000 key names. The response might contain fewer keys but will never contain more. */
803
+ maxKeys?: number;
804
+ /** The bucket name. */
805
+ name?: string;
806
+ /** NextContinuationToken is sent when isTruncated is true, which means there are more keys in the bucket that can be listed. The next list requests to S3 can be continued with this NextContinuationToken. NextContinuationToken is obfuscated and is not a real key. */
807
+ nextContinuationToken?: string;
808
+ /** Keys that begin with the indicated prefix. */
809
+ prefix?: string;
810
+ /** If StartAfter was sent with the request, it is included in the response. */
811
+ startAfter?: string;
812
+ }
813
+
814
+ /**
815
+ * A configured S3 bucket instance for managing files.
816
+ * The instance is callable to create S3File instances and provides methods
817
+ * for common operations.
818
+ *
819
+ * @example
820
+ * // Basic bucket setup
821
+ * const bucket = new S3Client({
822
+ * bucket: "my-bucket",
823
+ * accessKeyId: "key",
824
+ * secretAccessKey: "secret"
825
+ * });
826
+ *
827
+ * // Get file instance
828
+ * const file = bucket.file("image.jpg");
829
+ *
830
+ * // Common operations
831
+ * await bucket.write("data.json", JSON.stringify({hello: "world"}));
832
+ * const url = bucket.presign("file.pdf");
833
+ * await bucket.unlink("old.txt");
834
+ *
835
+ * @category Cloud Storage
836
+ */
837
+ class S3Client {
838
+ /**
839
+ * Create a new instance of an S3 bucket so that credentials can be managed
840
+ * from a single instance instead of being passed to every method.
841
+ *
842
+ * @param options The default options to use for the S3 client. Can be
843
+ * overriden by passing options to the methods.
844
+ * @returns A new S3Client instance
845
+ *
846
+ * ## Keep S3 credentials in a single instance
847
+ *
848
+ * @example
849
+ * const bucket = new Bun.S3Client({
850
+ * accessKeyId: "your-access-key",
851
+ * secretAccessKey: "your-secret-key",
852
+ * bucket: "my-bucket",
853
+ * endpoint: "https://s3.us-east-1.amazonaws.com",
854
+ * sessionToken: "your-session-token",
855
+ * });
856
+ *
857
+ * // S3Client is callable, so you can do this:
858
+ * const file = bucket.file("my-file.txt");
859
+ *
860
+ * // or this:
861
+ * await file.write("Hello Bun!");
862
+ * await file.text();
863
+ *
864
+ * // To delete the file:
865
+ * await bucket.delete("my-file.txt");
866
+ *
867
+ * // To write a file without returning the instance:
868
+ * await bucket.write("my-file.txt", "Hello Bun!");
869
+ *
870
+ */
871
+ constructor(options?: S3Options);
872
+
873
+ /**
874
+ * Creates an S3File instance for the given path.
875
+ *
876
+ * @param path The path to the file in the bucket
877
+ * @param options Additional S3 options to override defaults
878
+ * @returns An S3File instance
879
+ *
880
+ * @example
881
+ * const file = bucket.file("image.jpg");
882
+ * await file.write(imageData);
883
+ *
884
+ * const configFile = bucket.file("config.json", {
885
+ * type: "application/json",
886
+ * acl: "private"
887
+ * });
888
+ */
889
+ file(path: string, options?: S3Options): S3File;
890
+
891
+ /**
892
+ * Creates an S3File instance for the given path.
893
+ *
894
+ * @param path The path to the file in the bucket
895
+ * @param options S3 credentials and configuration options
896
+ * @returns An S3File instance
897
+ *
898
+ * @example
899
+ * const file = S3Client.file("image.jpg", credentials);
900
+ * await file.write(imageData);
901
+ *
902
+ * const configFile = S3Client.file("config.json", {
903
+ * ...credentials,
904
+ * type: "application/json",
905
+ * acl: "private"
906
+ * });
907
+ */
908
+ static file(path: string, options?: S3Options): S3File;
909
+
910
+ /**
911
+ * Writes data directly to a path in the bucket.
912
+ * Supports strings, buffers, streams, and web API types.
913
+ *
914
+ * @param path The path to the file in the bucket
915
+ * @param data The data to write to the file
916
+ * @param options Additional S3 options to override defaults
917
+ * @returns The number of bytes written
918
+ *
919
+ * @example
920
+ * // Write string
921
+ * await bucket.write("hello.txt", "Hello World");
922
+ *
923
+ * // Write JSON with type
924
+ * await bucket.write(
925
+ * "data.json",
926
+ * JSON.stringify({hello: "world"}),
927
+ * {type: "application/json"}
928
+ * );
929
+ *
930
+ * // Write from fetch
931
+ * const res = await fetch("https://example.com/data");
932
+ * await bucket.write("data.bin", res);
933
+ *
934
+ * // Write with ACL
935
+ * await bucket.write("public.html", html, {
936
+ * acl: "public-read",
937
+ * type: "text/html"
938
+ * });
939
+ */
940
+ write(
941
+ path: string,
942
+ data:
943
+ | string
944
+ | ArrayBufferView
945
+ | ArrayBuffer
946
+ | SharedArrayBuffer
947
+ | Request
948
+ | Response
949
+ | BunFile
950
+ | S3File
951
+ | Blob
952
+ | File
953
+ | Archive,
954
+ options?: S3Options,
955
+ ): Promise<number>;
956
+
957
+ /**
958
+ * Writes data directly to a path in the bucket.
959
+ * Supports strings, buffers, streams, and web API types.
960
+ *
961
+ * @param path The path to the file in the bucket
962
+ * @param data The data to write to the file
963
+ * @param options S3 credentials and configuration options
964
+ * @returns The number of bytes written
965
+ *
966
+ * @example
967
+ * // Write string
968
+ * await S3Client.write("hello.txt", "Hello World", credentials);
969
+ *
970
+ * // Write JSON with type
971
+ * await S3Client.write(
972
+ * "data.json",
973
+ * JSON.stringify({hello: "world"}),
974
+ * {
975
+ * ...credentials,
976
+ * type: "application/json"
977
+ * }
978
+ * );
979
+ *
980
+ * // Write from fetch
981
+ * const res = await fetch("https://example.com/data");
982
+ * await S3Client.write("data.bin", res, credentials);
983
+ *
984
+ * // Write with ACL
985
+ * await S3Client.write("public.html", html, {
986
+ * ...credentials,
987
+ * acl: "public-read",
988
+ * type: "text/html"
989
+ * });
990
+ */
991
+ static write(
992
+ path: string,
993
+ data:
994
+ | string
995
+ | ArrayBufferView
996
+ | ArrayBuffer
997
+ | SharedArrayBuffer
998
+ | Request
999
+ | Response
1000
+ | BunFile
1001
+ | S3File
1002
+ | Blob
1003
+ | File
1004
+ | Archive,
1005
+ options?: S3Options,
1006
+ ): Promise<number>;
1007
+
1008
+ /**
1009
+ * Generate a presigned URL for temporary access to a file.
1010
+ * Useful for generating upload/download URLs without exposing credentials.
1011
+ *
1012
+ * @param path The path to the file in the bucket
1013
+ * @param options Options for generating the presigned URL
1014
+ * @returns A presigned URL string
1015
+ *
1016
+ * @example
1017
+ * // Download URL
1018
+ * const downloadUrl = bucket.presign("file.pdf", {
1019
+ * expiresIn: 3600 // 1 hour
1020
+ * });
1021
+ *
1022
+ * // Upload URL
1023
+ * const uploadUrl = bucket.presign("uploads/image.jpg", {
1024
+ * method: "PUT",
1025
+ * expiresIn: 3600,
1026
+ * type: "image/jpeg",
1027
+ * acl: "public-read"
1028
+ * });
1029
+ *
1030
+ * // Long-lived public URL
1031
+ * const publicUrl = bucket.presign("public/doc.pdf", {
1032
+ * expiresIn: 7 * 24 * 60 * 60, // 7 days
1033
+ * acl: "public-read"
1034
+ * });
1035
+ */
1036
+ presign(path: string, options?: S3FilePresignOptions): string;
1037
+
1038
+ /**
1039
+ * Generate a presigned URL for temporary access to a file.
1040
+ * Useful for generating upload/download URLs without exposing credentials.
1041
+ *
1042
+ * @param path The path to the file in the bucket
1043
+ * @param options S3 credentials and presigned URL configuration
1044
+ * @returns A presigned URL string
1045
+ *
1046
+ * @example
1047
+ * // Download URL
1048
+ * const downloadUrl = S3Client.presign("file.pdf", {
1049
+ * ...credentials,
1050
+ * expiresIn: 3600 // 1 hour
1051
+ * });
1052
+ *
1053
+ * // Upload URL
1054
+ * const uploadUrl = S3Client.presign("uploads/image.jpg", {
1055
+ * ...credentials,
1056
+ * method: "PUT",
1057
+ * expiresIn: 3600,
1058
+ * type: "image/jpeg",
1059
+ * acl: "public-read"
1060
+ * });
1061
+ *
1062
+ * // Long-lived public URL
1063
+ * const publicUrl = S3Client.presign("public/doc.pdf", {
1064
+ * ...credentials,
1065
+ * expiresIn: 7 * 24 * 60 * 60, // 7 days
1066
+ * acl: "public-read"
1067
+ * });
1068
+ */
1069
+ static presign(path: string, options?: S3FilePresignOptions): string;
1070
+
1071
+ /**
1072
+ * Delete a file from the bucket.
1073
+ *
1074
+ * @param path The path to the file in the bucket
1075
+ * @param options Additional S3 options to override defaults
1076
+ * @returns A promise that resolves when deletion is complete
1077
+ *
1078
+ * @example
1079
+ * // Simple delete
1080
+ * await bucket.unlink("old-file.txt");
1081
+ *
1082
+ * // With error handling
1083
+ * try {
1084
+ * await bucket.unlink("file.dat");
1085
+ * console.log("File deleted");
1086
+ * } catch (err) {
1087
+ * console.error("Delete failed:", err);
1088
+ * }
1089
+ */
1090
+ unlink(path: string, options?: S3Options): Promise<void>;
1091
+
1092
+ /**
1093
+ * Delete a file from the bucket.
1094
+ *
1095
+ * @param path The path to the file in the bucket
1096
+ * @param options S3 credentials and configuration options
1097
+ * @returns A promise that resolves when deletion is complete
1098
+ *
1099
+ * @example
1100
+ * // Simple delete
1101
+ * await S3Client.unlink("old-file.txt", credentials);
1102
+ *
1103
+ * // With error handling
1104
+ * try {
1105
+ * await S3Client.unlink("file.dat", credentials);
1106
+ * console.log("File deleted");
1107
+ * } catch (err) {
1108
+ * console.error("Delete failed:", err);
1109
+ * }
1110
+ */
1111
+ static unlink(path: string, options?: S3Options): Promise<void>;
1112
+
1113
+ /**
1114
+ * Delete a file from the bucket.
1115
+ * Alias for {@link S3Client.unlink}.
1116
+ *
1117
+ * @param path The path to the file in the bucket
1118
+ * @param options Additional S3 options to override defaults
1119
+ * @returns A promise that resolves when deletion is complete
1120
+ *
1121
+ * @example
1122
+ * // Simple delete
1123
+ * await bucket.delete("old-file.txt");
1124
+ *
1125
+ * // With error handling
1126
+ * try {
1127
+ * await bucket.delete("file.dat");
1128
+ * console.log("File deleted");
1129
+ * } catch (err) {
1130
+ * console.error("Delete failed:", err);
1131
+ * }
1132
+ */
1133
+ delete(path: string, options?: S3Options): Promise<void>;
1134
+
1135
+ /**
1136
+ * Delete a file from the bucket.
1137
+ * Alias for {@link S3Client.unlink}.
1138
+ *
1139
+ * @param path The path to the file in the bucket
1140
+ * @param options S3 credentials and configuration options
1141
+ * @returns A promise that resolves when deletion is complete
1142
+ *
1143
+ * @example
1144
+ * // Simple delete
1145
+ * await S3Client.delete("old-file.txt", credentials);
1146
+ *
1147
+ * // With error handling
1148
+ * try {
1149
+ * await S3Client.delete("file.dat", credentials);
1150
+ * console.log("File deleted");
1151
+ * } catch (err) {
1152
+ * console.error("Delete failed:", err);
1153
+ * }
1154
+ */
1155
+ static delete(path: string, options?: S3Options): Promise<void>;
1156
+
1157
+ /**
1158
+ * Get the size of a file in bytes.
1159
+ * Uses HEAD request to efficiently get size.
1160
+ *
1161
+ * @param path The path to the file in the bucket
1162
+ * @param options Additional S3 options to override defaults
1163
+ * @returns A promise that resolves to the file size in bytes
1164
+ *
1165
+ * @example
1166
+ * // Get size
1167
+ * const bytes = await bucket.size("video.mp4");
1168
+ * console.log(`Size: ${bytes} bytes`);
1169
+ *
1170
+ * // Check if file is large
1171
+ * if (await bucket.size("data.zip") > 100 * 1024 * 1024) {
1172
+ * console.log("File is larger than 100MB");
1173
+ * }
1174
+ */
1175
+ size(path: string, options?: S3Options): Promise<number>;
1176
+
1177
+ /**
1178
+ * Get the size of a file in bytes.
1179
+ * Uses HEAD request to efficiently get size.
1180
+ *
1181
+ * @param path The path to the file in the bucket
1182
+ * @param options S3 credentials and configuration options
1183
+ * @returns A promise that resolves to the file size in bytes
1184
+ *
1185
+ * @example
1186
+ * // Get size
1187
+ * const bytes = await S3Client.size("video.mp4", credentials);
1188
+ * console.log(`Size: ${bytes} bytes`);
1189
+ *
1190
+ * // Check if file is large
1191
+ * if (await S3Client.size("data.zip", credentials) > 100 * 1024 * 1024) {
1192
+ * console.log("File is larger than 100MB");
1193
+ * }
1194
+ */
1195
+ static size(path: string, options?: S3Options): Promise<number>;
1196
+
1197
+ /**
1198
+ * Check if a file exists in the bucket.
1199
+ * Uses HEAD request to check existence.
1200
+ *
1201
+ * @param path The path to the file in the bucket
1202
+ * @param options Additional S3 options to override defaults
1203
+ * @returns A promise that resolves to true if the file exists, false otherwise
1204
+ *
1205
+ * @example
1206
+ * // Check existence
1207
+ * if (await bucket.exists("config.json")) {
1208
+ * const file = bucket.file("config.json");
1209
+ * const config = await file.json();
1210
+ * }
1211
+ *
1212
+ * // With error handling
1213
+ * try {
1214
+ * if (!await bucket.exists("required.txt")) {
1215
+ * throw new Error("Required file missing");
1216
+ * }
1217
+ * } catch (err) {
1218
+ * console.error("Check failed:", err);
1219
+ * }
1220
+ */
1221
+ exists(path: string, options?: S3Options): Promise<boolean>;
1222
+
1223
+ /**
1224
+ * Check if a file exists in the bucket.
1225
+ * Uses HEAD request to check existence.
1226
+ *
1227
+ * @param path The path to the file in the bucket
1228
+ * @param options S3 credentials and configuration options
1229
+ * @returns A promise that resolves to true if the file exists, false otherwise
1230
+ *
1231
+ * @example
1232
+ * // Check existence
1233
+ * if (await S3Client.exists("config.json", credentials)) {
1234
+ * const file = bucket.file("config.json");
1235
+ * const config = await file.json();
1236
+ * }
1237
+ *
1238
+ * // With error handling
1239
+ * try {
1240
+ * if (!await S3Client.exists("required.txt", credentials)) {
1241
+ * throw new Error("Required file missing");
1242
+ * }
1243
+ * } catch (err) {
1244
+ * console.error("Check failed:", err);
1245
+ * }
1246
+ */
1247
+ static exists(path: string, options?: S3Options): Promise<boolean>;
1248
+
1249
+ /**
1250
+ * Get the stat of a file in an S3-compatible storage service.
1251
+ *
1252
+ * @param path The path to the file in the bucket
1253
+ * @param options Additional S3 options to override defaults
1254
+ * @returns A promise that resolves to the file stats
1255
+ *
1256
+ * @example
1257
+ * const stat = await bucket.stat("my-file.txt");
1258
+ */
1259
+ stat(path: string, options?: S3Options): Promise<S3Stats>;
1260
+
1261
+ /**
1262
+ * Get the stat of a file in an S3-compatible storage service.
1263
+ *
1264
+ * @param path The path to the file in the bucket
1265
+ * @param options S3 credentials and configuration options
1266
+ * @returns A promise that resolves to the file stats
1267
+ *
1268
+ * @example
1269
+ * const stat = await S3Client.stat("my-file.txt", credentials);
1270
+ */
1271
+ static stat(path: string, options?: S3Options): Promise<S3Stats>;
1272
+
1273
+ /**
1274
+ * Returns some or all (up to 1,000) of the objects in a bucket with each request.
1275
+ *
1276
+ * You can use the request parameters as selection criteria to return a subset of the objects in a bucket.
1277
+ *
1278
+ * @param input Options for listing objects in the bucket
1279
+ * @param options Additional S3 options to override defaults
1280
+ * @returns A promise that resolves to the list response
1281
+ *
1282
+ * @example
1283
+ * // List (up to) 1000 objects in the bucket
1284
+ * const allObjects = await bucket.list();
1285
+ *
1286
+ * // List (up to) 500 objects under `uploads/` prefix, with owner field for each object
1287
+ * const uploads = await bucket.list({
1288
+ * prefix: 'uploads/',
1289
+ * maxKeys: 500,
1290
+ * fetchOwner: true,
1291
+ * });
1292
+ *
1293
+ * // Check if more results are available
1294
+ * if (uploads.isTruncated) {
1295
+ * // List next batch of objects under `uploads/` prefix
1296
+ * const moreUploads = await bucket.list({
1297
+ * prefix: 'uploads/',
1298
+ * maxKeys: 500,
1299
+ * startAfter: uploads.contents!.at(-1).key
1300
+ * fetchOwner: true,
1301
+ * });
1302
+ * }
1303
+ */
1304
+ list(
1305
+ input?: S3ListObjectsOptions | null,
1306
+ options?: Pick<S3Options, "accessKeyId" | "secretAccessKey" | "sessionToken" | "region" | "bucket" | "endpoint">,
1307
+ ): Promise<S3ListObjectsResponse>;
1308
+
1309
+ /**
1310
+ * Returns some or all (up to 1,000) of the objects in a bucket with each request.
1311
+ *
1312
+ * You can use the request parameters as selection criteria to return a subset of the objects in a bucket.
1313
+ *
1314
+ * @param input Options for listing objects in the bucket
1315
+ * @param options S3 credentials and configuration options
1316
+ * @returns A promise that resolves to the list response
1317
+ *
1318
+ * @example
1319
+ * // List (up to) 1000 objects in the bucket
1320
+ * const allObjects = await S3Client.list(null, credentials);
1321
+ *
1322
+ * // List (up to) 500 objects under `uploads/` prefix, with owner field for each object
1323
+ * const uploads = await S3Client.list({
1324
+ * prefix: 'uploads/',
1325
+ * maxKeys: 500,
1326
+ * fetchOwner: true,
1327
+ * }, credentials);
1328
+ *
1329
+ * // Check if more results are available
1330
+ * if (uploads.isTruncated) {
1331
+ * // List next batch of objects under `uploads/` prefix
1332
+ * const moreUploads = await S3Client.list({
1333
+ * prefix: 'uploads/',
1334
+ * maxKeys: 500,
1335
+ * startAfter: uploads.contents!.at(-1).key
1336
+ * fetchOwner: true,
1337
+ * }, credentials);
1338
+ * }
1339
+ */
1340
+ static list(
1341
+ input?: S3ListObjectsOptions | null,
1342
+ options?: Pick<S3Options, "accessKeyId" | "secretAccessKey" | "sessionToken" | "region" | "bucket" | "endpoint">,
1343
+ ): Promise<S3ListObjectsResponse>;
1344
+ }
1345
+
1346
+ /**
1347
+ * A default instance of S3Client
1348
+ *
1349
+ * Pulls credentials from environment variables. Use `new Bun.S3Client()` if you need to explicitly set credentials.
1350
+ *
1351
+ * @category Cloud Storage
1352
+ */
1353
+ var s3: S3Client;
1354
+ }