{"docsConfig":{"theme":"aspen","$schema":"https://mintlify.com/docs.json","name":"Bun 中文文档","colors":{"primary":"#ff73a8","light":"#ff73a8","dark":"#ff73a8"},"logo":{"light":"/logo/logo-with-wordmark-dark.svg","dark":"/logo/logo-with-wordmark-light.svg"},"favicon":"/logo/bun.png","appearance":{"default":"system"},"background":{"decoration":"gradient"},"navbar":{"links":[{"icon":"download","href":"/installation","label":"安装 Bun"}]},"footer":{"socials":{"x":"https://x.com/bunjavascript","github":"https://github.com/oven-sh/bun","discord":"https://bun.com/discord","youtube":"https://www.youtube.com/@bunjs"}},"seo":{"metatags":{"canonical":"https://bun.zhcndoc.com"}},"icons":{"library":"lucide"},"styling":{"codeblocks":{"theme":{"light":"github-light","dark":"dracula"}}},"contextual":{"options":["copy","view","claude","mcp","vscode"],"display":"header"},"integrations":{"telemetry":{"enabled":false}},"navigation":{"pages":[]}},"deployment":{"deploymentMetadataValue":{"hasAudioNarration":false,"customDomains":[],"gitSource":{"type":"github","owner":"local","repo":"local","deployBranch":"main","contentDirectory":"","isPrivate":true,"mountPath":"","label":"local","isBase":true},"buildId":"local","clientVersion":"0.0.4050"},"basePath":"","hasChatPermissions":false,"hasWebMcpPermissions":false,"toggles":[],"googleFontsInlined":false,"isLoggedInCli":false,"mintExport":{}},"customCss":[{"filePath":"style.css","content":".steps{margin-top:0}div[data-component-part=card-icon]>svg{mask-size:80%}.font-mono{font-weight:700!important}.nav-tabs .nav-tabs-item{font-size:.8rem!important}.mdx-content>span[data-as=p]{margin-bottom:2rem!important}.dark\\:bg-white\\/5:is(.dark *){background-color:rgb(155 155 155/5%)}ul#sidebar-group>li>a{font-size:.825rem;line-height:1rem;font-weight:500}pre.shiki{line-height:1.4rem;font-size:.8rem}.dark\\:ring-white\\/\\[0\\.14\\]:is(.dark *){border:1px solid rgb(255 255 255/.14)!important;--tw-ring-color:transparent}.ring-transparent{border:1px solid transparent!important}.code-block:has([data-component-part=code-block-header]) div[data-component-part=code-block-root],.code-group:has([data-component-part=code-group-tab-bar]) div[data-component-part=code-block-root]{border-top-right-radius:0!important;border-top-left-radius:0!important}div[data-component-part=card-icon] img,img.code-block-icon{background:0 0!important}html.dark .card-group .card:not(:hover){border:1px solid rgb(255 255 255/.1)!important}html:not(.dark) .card-group .card{border:1px solid rgb(var(--gray-200))!important}.dark div[data-component-part=card-content-container]{background:rgb(255 255 255/.03)}.card:hover{border-color:rgb(var(--gray-400)/var(--tw-border-opacity))!important}html.dark .shiki,html.dark .shiki span{background-color:transparent!important}.prose :where(hr):not(:where([class~=\"not-prose\"], [class~=\"not-prose\"] *)){margin-top:2rem!important;margin-bottom:2rem!important}.nav-tabs{width:100%!important}a[href=\"/docs/guides\"],a[href=\"/guides\"]{margin-left:auto!important}div[data-component-part=card-content-container]{height:100%!important}div#guides-list div[data-component-part=card-content-container]>:nth-child(2){height:100%;display:flex;flex-direction:column;justify-content:space-between!important}.code-block+.code-block[language=text]{margin-top:-32px;z-index:-1;border-top-right-radius:0;border-top-left-radius:0;border-top:none}.code-block+.code-block[language=text],.code-block+.code-block[language=text] div[data-component-part=code-block-root]{background-color:rgb(var(--gray-50))!important}html.dark .code-block+.code-block[language=text],html.dark .code-block+.code-block[language=text] div[data-component-part=code-block-root]{background-color:#16171e!important}.code-block+.code-block[language=text] div.absolute.top-3{display:none}.code-block:has(+.code-block[language=text]),.code-block:has(+.code-block[language=text]) div[data-component-part=code-block-root]{border-bottom-right-radius:0;border-bottom-left-radius:0}div.callout .code-block{margin-bottom:0}[language=shellscript] code span.line:not(:empty):has(span)::before{content:\"$ \";color:#6272a4;user-select:none}[language=powershell] code span.line:has(>span:first-child[style*=\"#6272A4\"])::before,[language=powershell] code span.line:has(>span:first-child[style*=\"color: rgb(98, 114, 164)\"])::before,[language=shellscript] code span.line:has(>span:first-child[style*=\"#6272A4\"])::before,[language=shellscript] code span.line:has(>span:first-child[style*=\"color: rgb(98, 114, 164)\"])::before{content:\"\"}[language=powershell] code span.line:not(:empty):has(span)::before{content:\"> \";color:#6272a4;user-select:none}.dark [data-component-part=code-block-root]:not(.has-line-numbers) .line-highlight,.dark [data-component-part=code-block-root]:not(.has-line-numbers) .line-highlight:after,.dark [data-component-part=code-block-root]:not(.has-line-numbers) .line-highlight:before{background:rgb(219 219 219/20%)!important}.dark[data-component-part=code-block-root]:not(.has-line-numbers) .line-highlight:before{border-color:#fff}[data-component-part=code-block-root]:not(.has-line-numbers) .line-highlight,[data-component-part=code-block-root]:not(.has-line-numbers) .line-highlight:after,[data-component-part=code-block-root]:not(.has-line-numbers) .line-highlight:before{background:rgb(var(--gray-200)/.5)!important}[data-component-part=code-block-root]:not(.has-line-numbers) .line-highlight:before{border-color:#acacac}"}],"page":{"pagePath":"guides","slug":"/guides","pageMetadata":{"title":"指南","description":"使用 Bun 完成常见任务的代码示例和操作指南","contextual":false,"mode":"center","href":"/guides/index"},"description":{"compiledSource":"\"use strict\";\nconst {jsx: _jsx} = arguments[0];\nconst {useMDXComponents: _provideComponents} = arguments[0];\nfunction _createMdxContent(props) {\n const _components = {\n p: \"p\",\n ..._provideComponents(),\n ...props.components\n };\n return _jsx(_components.p, {\n children: \"使用 Bun 完成常见任务的代码示例和操作指南\"\n });\n}\nfunction MDXContent(props = {}) {\n const {wrapper: MDXLayout} = {\n ..._provideComponents(),\n ...props.components\n };\n return MDXLayout ? _jsx(MDXLayout, {\n ...props,\n children: _jsx(_createMdxContent, {\n ...props\n })\n }) : _createMdxContent(props);\n}\nreturn {\n default: MDXContent\n};\n","frontmatter":{},"scope":{}},"pageType":"default","mdx":{"mdxSource":{"compiledSource":"\"use strict\";const{jsx:_jsx,jsxs:_jsxs}=arguments[0];const{useMDXComponents:_provideComponents}=arguments[0];const GuidesList=()=>{const{Card,Columns}=_provideComponents()||{};if(!Card)_missingMdxReference(`Card`,true);if(!Columns)_missingMdxReference(`Columns`,true);const guidesData={hero:{title:`Guides`,blurb:`A collection of code samples and walkthroughs for performing common tasks with Bun.`},featured:[{category:`Ecosystem`,title:`Use Tanstack Start with Bun`,href:`/guides/ecosystem/tanstack-start`,cta:`View guide`},{category:`Ecosystem`,title:`Use Next.js with Bun`,href:`/guides/ecosystem/nextjs`,cta:`View guide`},{category:`Ecosystem`,title:`Build a frontend using Vite and Bun`,href:`/guides/ecosystem/vite`,cta:`View guide`},{category:`Runtime`,title:`Install TypeScript declarations for Bun`,href:`/guides/runtime/typescript`,cta:`View guide`},{category:`HTTP`,title:`Write a simple HTTP server`,href:`/guides/http/simple`,cta:`View guide`},{category:`WebSocket`,title:`Build a simple WebSocket server`,href:`/guides/websocket/simple`,cta:`View guide`}],categories:[{key:`deployment`,title:`Deployment`,icon:`rocket`,items:[{title:`Deploy Bun on Vercel`,href:`/guides/deployment/vercel`},{title:`Deploy Bun on Railway`,href:`/guides/deployment/railway`},{title:`Deploy Bun on Render`,href:`/guides/deployment/render`}]},{key:`binary`,title:`Binary data`,icon:`binary`,items:[{title:`Convert an ArrayBuffer to an array of numbers`,href:`/guides/binary/arraybuffer-to-array`},{title:`Convert an ArrayBuffer to a Blob`,href:`/guides/binary/arraybuffer-to-blob`},{title:`Convert an ArrayBuffer to a Buffer`,href:`/guides/binary/arraybuffer-to-buffer`},{title:`Convert an ArrayBuffer to a string`,href:`/guides/binary/arraybuffer-to-string`},{title:`Convert an ArrayBuffer to a Uint8Array`,href:`/guides/binary/arraybuffer-to-typedarray`},{title:`Convert a Blob to an ArrayBuffer`,href:`/guides/binary/blob-to-arraybuffer`},{title:`Convert a Blob to a DataView`,href:`/guides/binary/blob-to-dataview`},{title:`Convert a Blob to a ReadableStream`,href:`/guides/binary/blob-to-stream`},{title:`Convert a Blob to a string`,href:`/guides/binary/blob-to-string`},{title:`Convert a Blob to a Uint8Array`,href:`/guides/binary/blob-to-typedarray`},{title:`Convert a Buffer to an ArrayBuffer`,href:`/guides/binary/buffer-to-arraybuffer`},{title:`Convert a Buffer to a blob`,href:`/guides/binary/buffer-to-blob`},{title:`Convert a Buffer to a ReadableStream`,href:`/guides/binary/buffer-to-readablestream`},{title:`Convert a Buffer to a string`,href:`/guides/binary/buffer-to-string`},{title:`Convert a Buffer to a Uint8Array`,href:`/guides/binary/buffer-to-typedarray`},{title:`Convert a DataView to a string`,href:`/guides/binary/dataview-to-string`},{title:`Convert a Uint8Array to an ArrayBuffer`,href:`/guides/binary/typedarray-to-arraybuffer`},{title:`Convert a Uint8Array to a Blob`,href:`/guides/binary/typedarray-to-blob`},{title:`Convert a Uint8Array to a Buffer`,href:`/guides/binary/typedarray-to-buffer`},{title:`Convert a Uint8Array to a DataView`,href:`/guides/binary/typedarray-to-dataview`},{title:`Convert a Uint8Array to a ReadableStream`,href:`/guides/binary/typedarray-to-readablestream`},{title:`Convert a Uint8Array to a string`,href:`/guides/binary/typedarray-to-string`}]},{key:`ecosystem`,title:`Ecosystem`,icon:`puzzle`,items:[{title:`Use Gel with Bun`,href:`/guides/ecosystem/gel`},{title:`Use Prisma ORM with Bun`,href:`/guides/ecosystem/prisma`},{title:`Use Prisma Postgres with Bun`,href:`/guides/ecosystem/prisma-postgres`},{title:`Create a Discord bot`,href:`/guides/ecosystem/discordjs`},{title:`Add Sentry to a Bun app`,href:`/guides/ecosystem/sentry`},{title:`Use Drizzle ORM with Bun`,href:`/guides/ecosystem/drizzle`},{title:`Build a React app with Bun`,href:`/guides/ecosystem/react`},{title:`Run Bun as a daemon with PM2`,href:`/guides/ecosystem/pm2`},{title:`Build an app with Nuxt and Bun`,href:`/guides/ecosystem/nuxt`},{title:`Build an app with Qwik and Bun`,href:`/guides/ecosystem/qwik`},{title:`Build an app with Astro and Bun`,href:`/guides/ecosystem/astro`},{title:`Build an app with Remix and Bun`,href:`/guides/ecosystem/remix`},{title:`Use TanStack Start with Bun`,href:`/guides/ecosystem/tanstack-start`},{title:`Run Bun as a daemon with systemd`,href:`/guides/ecosystem/systemd`},{title:`Build an app with Next.js and Bun`,href:`/guides/ecosystem/nextjs`},{title:`Build an app with SvelteKit and Bun`,href:`/guides/ecosystem/sveltekit`},{title:`Build a frontend using Vite and Bun`,href:`/guides/ecosystem/vite`},{title:`Build an app with SolidStart and Bun`,href:`/guides/ecosystem/solidstart`},{title:`Use Neon Postgres through Drizzle ORM`,href:`/guides/ecosystem/neon-drizzle`},{title:`Build an HTTP server using Hono and Bun`,href:`/guides/ecosystem/hono`},{title:`Use Neon's Serverless Postgres with Bun`,href:`/guides/ecosystem/neon-serverless-postgres`},{title:`Build an HTTP server using Elysia and Bun`,href:`/guides/ecosystem/elysia`},{title:`Containerize a Bun application with Docker`,href:`/guides/ecosystem/docker`},{title:`Build an HTTP server using Express and Bun`,href:`/guides/ecosystem/express`},{title:`Server-side render (SSR) a React component`,href:`/guides/ecosystem/ssr-react`},{title:`Read and write data to MongoDB using Mongoose and Bun`,href:`/guides/ecosystem/mongoose`}]},{key:`htmlrewriter`,title:`HTMLRewriter`,icon:`file-code-2`,items:[{title:`Extract links from a webpage using HTMLRewriter`,href:`/guides/html-rewriter/extract-links`},{title:`Extract social share images and Open Graph tags`,href:`/guides/html-rewriter/extract-social-meta`}]},{key:`http`,title:`HTTP`,icon:`globe`,items:[{title:`Common HTTP server usage`,href:`/guides/http/server`},{title:`Hot reload an HTTP server`,href:`/guides/http/hot`},{title:`Write a simple HTTP server`,href:`/guides/http/simple`},{title:`Start a cluster of HTTP servers`,href:`/guides/http/cluster`},{title:`Configure TLS on an HTTP server`,href:`/guides/http/tls`},{title:`Send an HTTP request using fetch`,href:`/guides/http/fetch`},{title:`Proxy HTTP requests using fetch()`,href:`/guides/http/proxy`},{title:`Stream a file as an HTTP Response`,href:`/guides/http/stream-file`},{title:`Upload files via HTTP using FormData`,href:`/guides/http/file-uploads`},{title:`fetch with unix domain sockets in Bun`,href:`/guides/http/fetch-unix`},{title:`Streaming HTTP Server with Async Iterators`,href:`/guides/http/stream-iterator`},{title:`Server-Sent Events (SSE)`,href:`/guides/http/sse`},{title:`Streaming HTTP Server with Node.js Streams`,href:`/guides/http/stream-node-streams-in-bun`}]},{key:`install`,title:`Package manager`,icon:`package`,items:[{title:`Add a dependency`,href:`/guides/install/add`},{title:`Add a Git dependency`,href:`/guides/install/add-git`},{title:`Add a peer dependency`,href:`/guides/install/add-peer`},{title:`Add a tarball dependency`,href:`/guides/install/add-tarball`},{title:`Add a trusted dependency`,href:`/guides/install/trusted`},{title:`Add an optional dependency`,href:`/guides/install/add-optional`},{title:`Add a development dependency`,href:`/guides/install/add-dev`},{title:`Using bun install with Artifactory`,href:`/guides/install/jfrog-artifactory`},{title:`Generate a yarn-compatible lockfile`,href:`/guides/install/yarnlock`},{title:`Migrate from npm install to bun install`,href:`/guides/install/from-npm-install-to-bun-install`},{title:`Configuring a monorepo using workspaces`,href:`/guides/install/workspaces`},{title:`Install a package under a different name`,href:`/guides/install/npm-alias`},{title:`Configure git to diff Bun's lockb lockfile`,href:`/guides/install/git-diff-bun-lockfile`},{title:`Install dependencies with Bun in GitHub Actions`,href:`/guides/install/cicd`},{title:`Override the default npm registry for bun install`,href:`/guides/install/custom-registry`},{title:`Using bun install with an Azure Artifacts npm registry`,href:`/guides/install/azure-artifacts`},{title:`Configure a private registry for an organization scope with bun install`,href:`/guides/install/registry-scope`}]},{key:`processes`,title:`Processes`,icon:`cpu`,items:[{title:`Read from stdin`,href:`/guides/process/stdin`},{title:`Listen for CTRL+C`,href:`/guides/process/ctrl-c`},{title:`Listen to OS signals`,href:`/guides/process/os-signals`},{title:`Spawn a child process`,href:`/guides/process/spawn`},{title:`Parse command-line arguments`,href:`/guides/process/argv`},{title:`Read stderr from a child process`,href:`/guides/process/spawn-stderr`},{title:`Read stdout from a child process`,href:`/guides/process/spawn-stdout`},{title:`Get the process uptime in nanoseconds`,href:`/guides/process/nanoseconds`},{title:`Spawn a child process and communicate using IPC`,href:`/guides/process/ipc`}]},{key:`read-file`,title:`Reading files`,icon:`file`,items:[{title:`Read a JSON file`,href:`/guides/read-file/json`},{title:`Check if a file exists`,href:`/guides/read-file/exists`},{title:`Read a file to a Buffer`,href:`/guides/read-file/buffer`},{title:`Read a file as a string`,href:`/guides/read-file/string`},{title:`Get the MIME type of a file`,href:`/guides/read-file/mime`},{title:`Read a file to a Uint8Array`,href:`/guides/read-file/uint8array`},{title:`Read a file to an ArrayBuffer`,href:`/guides/read-file/arraybuffer`},{title:`Watch a directory for changes`,href:`/guides/read-file/watch`},{title:`Read a file as a ReadableStream`,href:`/guides/read-file/stream`}]},{key:`runtime`,title:`Runtime`,icon:`bot`,items:[{title:`Delete files`,href:`/guides/runtime/delete-file`},{title:`Delete directories`,href:`/guides/runtime/delete-directory`},{title:`Import a JSON file`,href:`/guides/runtime/import-json`},{title:`Import a TOML file`,href:`/guides/runtime/import-toml`},{title:`Import a YAML file`,href:`/guides/runtime/import-yaml`},{title:`Run a Shell Command`,href:`/guides/runtime/shell`},{title:`Re-map import paths`,href:`/guides/runtime/tsconfig-paths`},{title:`Set a time zone in Bun`,href:`/guides/runtime/timezone`},{title:`Set environment variables`,href:`/guides/runtime/set-env`},{title:`Import a HTML file as text`,href:`/guides/runtime/import-html`},{title:`Read environment variables`,href:`/guides/runtime/read-env`},{title:`Build-time constants with --define`,href:`/guides/runtime/build-time-constants`},{title:`Debugging Bun with the web debugger`,href:`/guides/runtime/web-debugger`},{title:`Install and run Bun in GitHub Actions`,href:`/guides/runtime/cicd`},{title:`Install TypeScript declarations for Bun`,href:`/guides/runtime/typescript`},{title:`Debugging Bun with the VS Code extension`,href:`/guides/runtime/vscode-debugger`},{title:`Inspect memory usage using V8 heap snapshots`,href:`/guides/runtime/heap-snapshot`},{title:`Define and replace static globals \u0026 constants`,href:`/guides/runtime/define-constant`},{title:`Codesign a single-file JavaScript executable on macOS`,href:`/guides/runtime/codesign-macos-executable`}]},{key:`streams`,title:`Streams`,icon:`waves`,items:[{title:`Convert a ReadableStream to JSON`,href:`/guides/streams/to-json`},{title:`Convert a Node.js Readable to JSON`,href:`/guides/streams/node-readable-to-json`},{title:`Convert a ReadableStream to a Blob`,href:`/guides/streams/to-blob`},{title:`Convert a Node.js Readable to a Blob`,href:`/guides/streams/node-readable-to-blob`},{title:`Convert a ReadableStream to a Buffer`,href:`/guides/streams/to-buffer`},{title:`Convert a ReadableStream to a string`,href:`/guides/streams/to-string`},{title:`Convert a Node.js Readable to a string`,href:`/guides/streams/node-readable-to-string`},{title:`Convert a ReadableStream to a Uint8Array`,href:`/guides/streams/to-typedarray`},{title:`Convert a ReadableStream to an ArrayBuffer`,href:`/guides/streams/to-arraybuffer`},{title:`Convert a Node.js Readable to an Uint8Array`,href:`/guides/streams/node-readable-to-uint8array`},{title:`Convert a Node.js Readable to an ArrayBuffer`,href:`/guides/streams/node-readable-to-arraybuffer`},{title:`Convert a ReadableStream to an array of chunks`,href:`/guides/streams/to-array`}]},{key:`test`,title:`Test runner`,icon:`test-tube`,items:[{title:`Mock functions in bun test`,href:`/guides/test/mock-functions`},{title:`Spy on methods in bun test`,href:`/guides/test/spy-on`},{title:`Using Testing Library with Bun`,href:`/guides/test/testing-library`},{title:`Update snapshots in bun test`,href:`/guides/test/update-snapshots`},{title:`Run tests in watch mode with Bun`,href:`/guides/test/watch-mode`},{title:`Use snapshot testing in bun test`,href:`/guides/test/snapshot`},{title:`Bail early with the Bun test runner`,href:`/guides/test/bail`},{title:`Skip tests with the Bun test runner`,href:`/guides/test/skip-tests`},{title:`Migrate from Jest to Bun's test runner`,href:`/guides/test/migrate-from-jest`},{title:`Run your tests with the Bun test runner`,href:`/guides/test/run-tests`},{title:`Set the system time in Bun's test runner`,href:`/guides/test/mock-clock`},{title:`Write browser DOM tests with Bun and happy-dom`,href:`/guides/test/happy-dom`},{title:`Set a per-test timeout with the Bun test runner`,href:`/guides/test/timeout`},{title:`Mark a test as a \"todo\" with the Bun test runner`,href:`/guides/test/todo-tests`},{title:`Re-run tests multiple times with the Bun test runner`,href:`/guides/test/rerun-each`},{title:`Set a code coverage threshold with the Bun test runner`,href:`/guides/test/coverage-threshold`},{title:`Selectively run tests concurrently with glob patterns`,href:`/guides/test/concurrent-test-glob`},{title:`Generate code coverage reports with the Bun test runner`,href:`/guides/test/coverage`},{title:`import, require, and test Svelte components with bun test`,href:`/guides/test/svelte-test`}]},{key:`utilities`,title:`Utilities`,icon:`wrench`,items:[{title:`Hash a password`,href:`/guides/util/hash-a-password`},{title:`Generate a UUID`,href:`/guides/util/javascript-uuid`},{title:`Escape an HTML string`,href:`/guides/util/escape-html`},{title:`Get the current Bun version`,href:`/guides/util/version`},{title:`Encode and decode base64 strings`,href:`/guides/util/base64`},{title:`Check if two objects are deeply equal`,href:`/guides/util/deep-equals`},{title:`Detect when code is executed with Bun`,href:`/guides/util/detect-bun`},{title:`Get the directory of the current file`,href:`/guides/util/import-meta-dir`},{title:`Get the file name of the current file`,href:`/guides/util/import-meta-file`},{title:`Convert a file URL to an absolute path`,href:`/guides/util/file-url-to-path`},{title:`Compress and decompress data with gzip`,href:`/guides/util/gzip`},{title:`Convert an absolute path to a file URL`,href:`/guides/util/path-to-file-url`},{title:`Get the path to an executable bin file`,href:`/guides/util/which-path-to-executable-bin`},{title:`Sleep for a fixed number of milliseconds`,href:`/guides/util/sleep`},{title:`Compress and decompress data with DEFLATE`,href:`/guides/util/deflate`},{title:`Get the absolute path of the current file`,href:`/guides/util/import-meta-path`},{title:`Check if the current file is the entrypoint`,href:`/guides/util/entrypoint`},{title:`Get the absolute path to the current entrypoint`,href:`/guides/util/main`}]},{key:`websocket`,title:`WebSocket`,icon:`radio`,items:[{title:`Build a simple WebSocket server`,href:`/guides/websocket/simple`},{title:`Enable compression for WebSocket messages`,href:`/guides/websocket/compression`},{title:`Build a publish-subscribe WebSocket server`,href:`/guides/websocket/pubsub`},{title:`Set per-socket contextual data on a WebSocket`,href:`/guides/websocket/context`}]},{key:`write-file`,title:`Writing files`,icon:`file-pen`,items:[{title:`Delete a file`,href:`/guides/write-file/unlink`},{title:`Write to stdout`,href:`/guides/write-file/stdout`},{title:`Write a Blob to a file`,href:`/guides/write-file/blob`},{title:`Write a file to stdout`,href:`/guides/write-file/cat`},{title:`Append content to a file`,href:`/guides/write-file/append`},{title:`Write a string to a file`,href:`/guides/write-file/basic`},{title:`Write a file incrementally`,href:`/guides/write-file/filesink`},{title:`Write a Response to a file`,href:`/guides/write-file/response`},{title:`Copy a file to another location`,href:`/guides/write-file/file-cp`},{title:`Write a ReadableStream to a file`,href:`/guides/write-file/stream`}]}]};return _jsxs(`div`,{id:`guides-list`,children:[_jsxs(`div`,{className:`mint-mb-12`,children:[_jsx(`h2`,{className:`mint-text-2xl mint-font-bold mint-mb-6`,children:`Featured`}),_jsx(Columns,{cols:3,children:guidesData.featured.map(g=>_jsx(Card,{title:g.title,href:g.href,cta:g.cta},g.href))})]}),_jsxs(`div`,{className:`mint-mb-8`,children:[_jsx(`h2`,{className:`mint-text-2xl mint-font-bold mint-mb-6`,children:`All Guides`}),guidesData.categories.map(category=>_jsxs(`div`,{className:`mint-mb-8`,children:[_jsx(`h3`,{className:`mint-text-xl mint-font-semibold mint-mb-4 mint-flex mint-items-center mint-gap-2`,children:category.title}),_jsx(Columns,{cols:3,children:category.items.map(guide=>_jsx(Card,{title:guide.title,description:` `,href:guide.href,cta:``},guide.href))})]},category.key))]})]})};function _createMdxContent(props){const{_MdxComponentBoundary}={..._provideComponents(),...props.components};if(!_MdxComponentBoundary)_missingMdxReference(`_MdxComponentBoundary`,true);return _jsx(_MdxComponentBoundary,{name:`GuidesList`,children:_jsx(GuidesList,{})})}function MDXContent(props={}){const{wrapper:MDXLayout}={..._provideComponents(),...props.components};return MDXLayout?_jsx(MDXLayout,{...props,children:_jsx(_createMdxContent,{...props})}):_createMdxContent(props)}return{GuidesList,default:MDXContent};function _missingMdxReference(id,component){throw new Error(`Expected `+(component?`component`:`object`)+\" `\"+id+\"` to be defined: you likely forgot to import, pass, or provide it.\")}","frontmatter":{},"scope":{"codeStyling":{"theme":{"light":"github-light","dark":"dracula"}},"config":{},"pageMetadata":{"title":"指南","description":"使用 Bun 完成常见任务的代码示例和操作指南","contextual":false,"mode":"center","href":"/guides/index"}}},"mdxSourceWithNoJs":null,"noJsSplices":[[27,38,""],[130,17143,"null;function _creat"]]},"mdxExtracts":{"tableOfContents":[],"codeExamples":{}},"jsLinks":["/_mintlify/custom/localhost/71a8c2a91b354e86/normalize-internal-links.js","/_mintlify/custom/localhost/5b9ba7e549301f2f/zhcndoc.js"],"dynamicCss":".mint-mb-12 {\n margin-bottom: 3rem\n}\n.mint-mb-4 {\n margin-bottom: 1rem\n}\n.mint-mb-6 {\n margin-bottom: 1.5rem\n}\n.mint-mb-8 {\n margin-bottom: 2rem\n}\n.mint-flex {\n display: flex\n}\n.mint-items-center {\n align-items: center\n}\n.mint-gap-2 {\n gap: 0.5rem\n}\n.mint-text-2xl {\n font-size: 1.5rem;\n line-height: 2rem\n}\n.mint-text-xl {\n font-size: 1.25rem;\n line-height: 1.75rem\n}\n.mint-font-bold {\n font-weight: 700\n}\n.mint-font-semibold {\n font-weight: 600\n}","subdomain":"localhost","siteName":"Bun 中文文档","title":"指南 - Bun 中文文档","navMaps":{"firstHrefInVersion":{},"firstHrefInLanguage":{}},"originalFileLocation":"guides/index.mdx"},"headHtml":"\u003cscript data-mint-head>(function(){var d=document.documentElement,p=null;if(!p){try{p=localStorage.getItem(\"isDarkMode\")}catch(e){}if(p==='true')p='dark';else if(p==='false')p='light';if(p!=='light'\u0026\u0026p!=='dark'\u0026\u0026p!=='system')p=\"system\"}var r=p==='system'?(matchMedia(\"(prefers-color-scheme: dark)\").matches?'dark':'light'):p;d.classList.remove(r==='dark'?'light':'dark');d.classList.add(r);d.setAttribute(\"data-theme-preference\",p)})();\u003c/script>\u003cmeta data-mint-head name=\"description\" content=\"使用 Bun 完成常见任务的代码示例和操作指南\">\u003cmeta data-mint-head name=\"application-name\" content=\"Bun 中文文档\">\u003cmeta data-mint-head name=\"generator\" content=\"Mintlify\">\u003clink data-mint-head rel=\"apple-touch-icon\" type=\"image/png\" sizes=\"180x180\" href=\"/favicons/apple-touch-icon.png\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"32x32\" href=\"/favicons/favicon-32x32.png\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"16x16\" href=\"/favicons/favicon-16x16.png\">\u003clink data-mint-head rel=\"shortcut icon\" type=\"image/x-icon\" href=\"/favicons/favicon.ico\">\u003cmeta data-mint-head property=\"og:title\" content=\"指南 - Bun 中文文档\">\u003cmeta data-mint-head property=\"og:description\" content=\"使用 Bun 完成常见任务的代码示例和操作指南\">\u003cmeta data-mint-head property=\"og:site_name\" content=\"Bun 中文文档\">\u003cmeta data-mint-head property=\"og:url\" content=\"https://bun.zhcndoc.com/guides\">\u003cmeta data-mint-head property=\"og:type\" content=\"website\">\u003cmeta data-mint-head name=\"twitter:card\" content=\"summary_large_image\">\u003cmeta data-mint-head name=\"twitter:title\" content=\"指南 - Bun 中文文档\">\u003cmeta data-mint-head name=\"twitter:description\" content=\"使用 Bun 完成常见任务的代码示例和操作指南\">\u003cmeta data-mint-head name=\"msapplication-config\" content=\"/favicons/browserconfig.xml\">\u003cmeta data-mint-head name=\"apple-mobile-web-app-title\" content=\"Bun 中文文档\">\u003cmeta data-mint-head name=\"msapplication-TileColor\" content=\"#ff73a8\">\u003clink data-mint-head rel=\"canonical\" href=\"https://bun.zhcndoc.com/guides\">\u003clink data-mint-head rel=\"alternate\" type=\"application/xml\" href=\"/sitemap.xml\">\u003clink data-mint-head rel=\"alternate\" type=\"text/markdown\" href=\"/guides.md\">\u003cscript data-mint-head type=\"application/ld+json\">{\"@context\":\"https://schema.org\",\"@type\":\"WebSite\",\"name\":\"Bun 中文文档\",\"creator\":{\"@type\":\"Organization\",\"name\":\"Mintlify\",\"url\":\"https://mintlify.com\"}}\u003c/script>","siteName":"Bun 中文文档","nav":{"tabs":[{"tab":"运行时","icon":"cog","pages":[{"title":"运行时","href":""}]},{"tab":"包管理器","icon":"box","pages":[{"title":"包管理器","href":"/pm/cli/install"}]},{"tab":"打包器","icon":"combine","pages":[{"title":"打包器","href":"/bundler"}]},{"tab":"测试运行器","icon":"flask-conical","pages":[{"title":"测试运行器","href":"/test"}]},{"tab":"指南","icon":"map","groups":[{"group":"概述","icon":"globe","pages":[{"title":"指南","mode":"center","href":"/guides"}]},{"group":"部署","icon":"rocket","pages":[{"title":"在 Vercel 上部署 Bun 应用","sidebarTitle":"在 Vercel 上部署","mode":"center","href":"/guides/deployment/vercel"},{"title":"在 Railway 上部署 Bun 应用","sidebarTitle":"在 Railway 上部署","mode":"center","href":"/guides/deployment/railway"},{"title":"在 Render 上部署 Bun 应用","sidebarTitle":"在 Render 上部署","mode":"center","href":"/guides/deployment/render"},{"title":"在 AWS Lambda 上部署 Bun 应用","sidebarTitle":"在 AWS Lambda 上部署","mode":"center","href":"/guides/deployment/aws-lambda"},{"title":"在 DigitalOcean 上部署 Bun 应用","sidebarTitle":"在 DigitalOcean 上部署","mode":"center","href":"/guides/deployment/digital-ocean"},{"title":"在 Google Cloud Run 上部署 Bun 应用","sidebarTitle":"在 Google Cloud Run 上部署","mode":"center","href":"/guides/deployment/google-cloud-run"}]},{"group":"运行时与调试","icon":"bug","pages":[{"title":"为 Bun 安装 TypeScript 声明文件","sidebarTitle":"TypeScript 类型","mode":"center","href":"/guides/runtime/typescript"},{"title":"重新映射导入路径","sidebarTitle":"重新映射导入路径","mode":"center","href":"/guides/runtime/tsconfig-paths"},{"title":"使用 VS Code 扩展调试 Bun","sidebarTitle":"VS Code 调试器","mode":"center","href":"/guides/runtime/vscode-debugger"},{"title":"使用网页调试器调试 Bun","sidebarTitle":"网页调试器","mode":"center","href":"/guides/runtime/web-debugger"},{"title":"使用 V8 堆快照检查内存使用情况","sidebarTitle":"堆快照","mode":"center","href":"/guides/runtime/heap-snapshot"},{"title":"使用 --define 实现构建时常量","sidebarTitle":"构建时常量","mode":"center","href":"/guides/runtime/build-time-constants"},{"title":"定义并替换静态全局变量和常量","sidebarTitle":"定义常量","mode":"center","href":"/guides/runtime/define-constant"},{"title":"在 GitHub Actions 中安装并运行 Bun","sidebarTitle":"GitHub Actions","mode":"center","href":"/guides/runtime/cicd"},{"title":"在 macOS 上为单文件 JavaScript 可执行文件进行代码签名","sidebarTitle":"macOS 上的代码签名","mode":"center","href":"/guides/runtime/codesign-macos-executable"}]},{"group":"实用工具","icon":"wrench","pages":[{"title":"将 Bun 升级到最新版本","sidebarTitle":"升级 Bun","mode":"center","href":"/guides/util/upgrade"},{"title":"检测代码何时在 Bun 中执行","sidebarTitle":"检测 Bun","mode":"center","href":"/guides/util/detect-bun"},{"title":"获取当前 Bun 版本","sidebarTitle":"获取 Bun 版本","mode":"center","href":"/guides/util/version"},{"title":"密码哈希","sidebarTitle":"密码哈希","mode":"center","href":"/guides/util/hash-a-password"},{"title":"生成 UUID","sidebarTitle":"生成 UUID","mode":"center","href":"/guides/util/javascript-uuid"},{"title":"编码和解码 base64 数据","sidebarTitle":"Base64 编码","mode":"center","href":"/guides/util/base64"},{"title":"使用 gzip 压缩和解压数据","sidebarTitle":"Gzip 压缩","mode":"center","href":"/guides/util/gzip"},{"title":"使用 DEFLATE 进行数据压缩和解压","sidebarTitle":"DEFLATE 压缩","mode":"center","href":"/guides/util/deflate"},{"title":"转义 HTML 字符串","sidebarTitle":"转义 HTML","mode":"center","href":"/guides/util/escape-html"},{"title":"检查两个对象是否深度相等","sidebarTitle":"深度相等","mode":"center","href":"/guides/util/deep-equals"},{"title":"固定毫秒数的休眠","sidebarTitle":"休眠","mode":"center","href":"/guides/util/sleep"},{"title":"将文件 URL 转换为绝对路径","sidebarTitle":"文件 URL 转路径","mode":"center","href":"/guides/util/file-url-to-path"},{"title":"将绝对路径转换为文件 URL","sidebarTitle":"路径转文件 URL","mode":"center","href":"/guides/util/path-to-file-url"},{"title":"获取可执行二进制文件的路径","sidebarTitle":"查找可执行文件路径","mode":"center","href":"/guides/util/which-path-to-executable-bin"},{"title":"获取当前文件的目录","sidebarTitle":"import.meta.dir","mode":"center","href":"/guides/util/import-meta-dir"},{"title":"获取当前文件的文件名","sidebarTitle":"import.meta.file","mode":"center","href":"/guides/util/import-meta-file"},{"title":"获取当前文件的绝对路径","sidebarTitle":"import.meta.path","mode":"center","href":"/guides/util/import-meta-path"},{"title":"检查当前文件是否为入口点","sidebarTitle":"检查入口点","mode":"center","href":"/guides/util/entrypoint"},{"title":"获取当前入口文件的绝对路径","sidebarTitle":"获取入口文件路径","mode":"center","href":"/guides/util/main"}]},{"group":"生态系统与框架","icon":"puzzle","pages":[{"title":"使用 Astro 和 Bun 构建应用","sidebarTitle":"Astro 与 Bun","mode":"center","href":"/guides/ecosystem/astro"},{"title":"创建一个 Discord 机器人","sidebarTitle":"使用 Bun 的 Discord.js","mode":"center","href":"/guides/ecosystem/discordjs"},{"title":"使用 Docker 容器化 Bun 应用程序","sidebarTitle":"使用 Docker 的 Bun","mode":"center","href":"/guides/ecosystem/docker"},{"title":"在 Bun 中使用 Drizzle ORM","sidebarTitle":"Drizzle 与 Bun","mode":"center","href":"/guides/ecosystem/drizzle"},{"title":"在 Bun 中使用 Gel","sidebarTitle":"Gel 与 Bun","mode":"center","href":"/guides/ecosystem/gel"},{"title":"使用 Elysia 和 Bun 构建 HTTP 服务器","sidebarTitle":"Elysia 与 Bun","mode":"center","href":"/guides/ecosystem/elysia"},{"title":"使用 Express 和 Bun 构建 HTTP 服务器","sidebarTitle":"Express 与 Bun","mode":"center","href":"/guides/ecosystem/express"},{"title":"使用 Hono 和 Bun 构建 HTTP 服务器","sidebarTitle":"Hono 与 Bun","mode":"center","href":"/guides/ecosystem/hono"},{"title":"使用 Mongoose 和 Bun 读写 MongoDB 数据","sidebarTitle":"Mongoose 与 Bun","mode":"center","href":"/guides/ecosystem/mongoose"},{"title":"使用 Drizzle ORM 连接 Neon Postgres","sidebarTitle":"使用 Bun 的 Neon Drizzle","mode":"center","href":"/guides/ecosystem/neon-drizzle"},{"title":"使用 Neon 的无服务器 Postgres 结合 Bun","sidebarTitle":"Neon 无服务器 Postgres 与 Bun","mode":"center","href":"/guides/ecosystem/neon-serverless-postgres"},{"title":"使用 Next.js 和 Bun 构建应用","sidebarTitle":"Next.js 与 Bun","mode":"center","href":"/guides/ecosystem/nextjs"},{"title":"使用 Nuxt 和 Bun 构建应用","sidebarTitle":"Nuxt 搭配 Bun","mode":"center","href":"/guides/ecosystem/nuxt"},{"title":"使用 PM2 作为守护进程运行 Bun","sidebarTitle":"PM2 与 Bun","mode":"center","href":"/guides/ecosystem/pm2"},{"title":"在 Bun 中使用 Prisma","sidebarTitle":"Prisma ORM 与 Bun","mode":"center","href":"/guides/ecosystem/prisma"},{"title":"在 Bun 中使用 Prisma Postgres","sidebarTitle":"在 Bun 中使用 Prisma Postgres","mode":"center","href":"/guides/ecosystem/prisma-postgres"},{"title":"使用 Qwik 和 Bun 构建应用","sidebarTitle":"Qwik 与 Bun","mode":"center","href":"/guides/ecosystem/qwik"},{"title":"使用 Bun 构建 React 应用","sidebarTitle":"React 与 Bun","mode":"center","href":"/guides/ecosystem/react"},{"title":"使用 Remix 和 Bun 构建应用","sidebarTitle":"使用 Remix 和 Bun","mode":"center","href":"/guides/ecosystem/remix"},{"title":"使用 Bun 启动 TanStack Start","sidebarTitle":"使用 Bun 启动 TanStack Start","mode":"center","href":"/guides/ecosystem/tanstack-start"},{"title":"在 Bun 应用中添加 Sentry","sidebarTitle":"Bun 中使用 Sentry","mode":"center","href":"/guides/ecosystem/sentry"},{"title":"使用 SolidStart 和 Bun 构建应用","sidebarTitle":"SolidStart 与 Bun","mode":"center","href":"/guides/ecosystem/solidstart"},{"title":"服务器端渲染(SSR)React 组件","sidebarTitle":"使用 Bun 进行 SSR React","mode":"center","href":"/guides/ecosystem/ssr-react"},{"title":"使用 SvelteKit 和 Bun 构建应用","sidebarTitle":"SvelteKit 与 Bun","mode":"center","href":"/guides/ecosystem/sveltekit"},{"title":"使用 systemd 将 Bun 作为守护进程运行","sidebarTitle":"systemd 与 Bun","mode":"center","href":"/guides/ecosystem/systemd"},{"title":"使用 Vite 和 Bun 构建前端","sidebarTitle":"Vite 与 Bun","mode":"center","href":"/guides/ecosystem/vite"},{"title":"使用 Bun 连接 Upstash Redis","sidebarTitle":"Bun 配合 Upstash","mode":"center","href":"/guides/ecosystem/upstash"}]},{"group":"HTTP 与网络","icon":"globe","pages":[{"title":"常见的 HTTP 服务器用法","sidebarTitle":"使用 Bun 的 HTTP 服务器","mode":"center","href":"/guides/http/server"},{"title":"编写一个简单的 HTTP 服务器","sidebarTitle":"使用 Bun 创建简单 HTTP 服务器","mode":"center","href":"/guides/http/simple"},{"title":"使用 fetch 发送 HTTP 请求","sidebarTitle":"Bun 中的 Fetch","mode":"center","href":"/guides/http/fetch"},{"title":"热重载 HTTP 服务器","sidebarTitle":"热重载 HTTP 服务器","mode":"center","href":"/guides/http/hot"},{"title":"启动 HTTP 服务器集群","sidebarTitle":"启动 HTTP 服务器集群","mode":"center","href":"/guides/http/cluster"},{"title":"在 HTTP 服务器上配置 TLS","sidebarTitle":"配置 TLS","mode":"center","href":"/guides/http/tls"},{"title":"使用 fetch() 代理 HTTP 请求","sidebarTitle":"使用 fetch() 代理 HTTP 请求","mode":"center","href":"/guides/http/proxy"},{"title":"将文件作为 HTTP 响应流式传输","sidebarTitle":"流式文件响应","mode":"center","href":"/guides/http/stream-file"},{"title":"使用 FormData 通过 HTTP 上传文件","sidebarTitle":"使用 FormData 通过 HTTP 上传文件","mode":"center","href":"/guides/http/file-uploads"},{"title":"在 Bun 中通过 unix 域套接字进行 fetch","sidebarTitle":"使用 unix 域套接字的 Fetch","mode":"center","href":"/guides/http/fetch-unix"},{"title":"使用异步迭代器的流式 HTTP 服务器","sidebarTitle":"使用迭代器流式传输","mode":"center","href":"/guides/http/stream-iterator"},{"title":"使用 Bun 的服务器发送事件(SSE)","sidebarTitle":"服务器发送事件","mode":"center","href":"/guides/http/sse"},{"title":"使用 Node.js 流的流式 HTTP 服务器","sidebarTitle":"使用 Node.js 流","mode":"center","href":"/guides/http/stream-node-streams-in-bun"}]},{"group":"WebSocket","icon":"radio","pages":[{"title":"构建一个简单的 WebSocket 服务器","sidebarTitle":"简单服务器","mode":"center","href":"/guides/websocket/simple"},{"title":"构建一个发布-订阅 WebSocket 服务器","sidebarTitle":"发布-订阅服务器","mode":"center","href":"/guides/websocket/pubsub"},{"title":"在 WebSocket 上设置每个 socket 的上下文数据","sidebarTitle":"上下文数据","mode":"center","href":"/guides/websocket/context"},{"title":"启用 WebSocket 消息压缩","sidebarTitle":"启用压缩","mode":"center","href":"/guides/websocket/compression"}]},{"group":"进程与系统","icon":"cpu","pages":[{"title":"启动子进程","sidebarTitle":"启动子进程","mode":"center","href":"/guides/process/spawn"},{"title":"从子进程读取标准输出","sidebarTitle":"读取标准输出","mode":"center","href":"/guides/process/spawn-stdout"},{"title":"从子进程读取 stderr","sidebarTitle":"读取 stderr","mode":"center","href":"/guides/process/spawn-stderr"},{"title":"解析命令行参数","sidebarTitle":"解析命令行参数","mode":"center","href":"/guides/process/argv"},{"title":"从 stdin 读取","sidebarTitle":"从 stdin 读取","mode":"center","href":"/guides/process/stdin"},{"title":"派生子进程并使用 IPC 通信","sidebarTitle":"派生子进程并使用 IPC 通信","mode":"center","href":"/guides/process/ipc"},{"title":"监听 CTRL+C","sidebarTitle":"监听 CTRL+C","mode":"center","href":"/guides/process/ctrl-c"},{"title":"监听操作系统信号","sidebarTitle":"操作系统信号","mode":"center","href":"/guides/process/os-signals"},{"title":"以纳秒为单位获取进程运行时间","sidebarTitle":"进程运行时间","mode":"center","href":"/guides/process/nanoseconds"},{"title":"运行 Shell 命令","sidebarTitle":"运行 shell 命令","mode":"center","href":"/guides/runtime/shell"},{"title":"在 Bun 中设置时区","sidebarTitle":"设置时区","mode":"center","href":"/guides/runtime/timezone"},{"title":"设置环境变量","sidebarTitle":"设置环境变量","mode":"center","href":"/guides/runtime/set-env"},{"title":"读取环境变量","sidebarTitle":"读取环境变量","mode":"center","href":"/guides/runtime/read-env"}]},{"group":"包管理器","icon":"package","pages":[{"title":"添加依赖","sidebarTitle":"添加依赖","mode":"center","href":"/guides/install/add"},{"title":"添加开发依赖","sidebarTitle":"添加开发依赖","mode":"center","href":"/guides/install/add-dev"},{"title":"添加可选依赖","sidebarTitle":"添加可选依赖","mode":"center","href":"/guides/install/add-optional"},{"title":"添加一个 peer 依赖","sidebarTitle":"添加一个 peer 依赖","mode":"center","href":"/guides/install/add-peer"},{"title":"添加 Git 依赖","sidebarTitle":"添加 Git 依赖","mode":"center","href":"/guides/install/add-git"},{"title":"添加一个 tarball 依赖","sidebarTitle":"添加一个 tarball 依赖","mode":"center","href":"/guides/install/add-tarball"},{"title":"以不同名称安装包","sidebarTitle":"使用别名安装","mode":"center","href":"/guides/install/npm-alias"},{"title":"使用 workspaces 配置 monorepo","sidebarTitle":"Bun 的 Workspaces","mode":"center","href":"/guides/install/workspaces"},{"title":"覆盖 bun install 的默认 npm registry","sidebarTitle":"覆盖默认的 npm registry","mode":"center","href":"/guides/install/custom-registry"},{"title":"使用 bun install 为组织作用域配置私有注册表","sidebarTitle":"配置作用域注册表","mode":"center","href":"/guides/install/registry-scope"},{"title":"使用 bun install 配合 Azure Artifacts npm 注册表","sidebarTitle":"在 Bun 中使用 Azure Artifacts","mode":"center","href":"/guides/install/azure-artifacts"},{"title":"使用 bun install 配合 Artifactory","sidebarTitle":"使用 Bun 的 JFrog Artifactory","mode":"center","href":"/guides/install/jfrog-artifactory"},{"title":"添加受信任的依赖","sidebarTitle":"添加受信任的依赖","mode":"center","href":"/guides/install/trusted"},{"title":"生成兼容 yarn 的锁文件","sidebarTitle":"生成兼容 yarn 的锁文件","mode":"center","href":"/guides/install/yarnlock"},{"title":"从 npm install 迁移到 bun install","sidebarTitle":"从 npm 迁移到 bun","mode":"center","href":"/guides/install/from-npm-install-to-bun-install"},{"title":"配置 git 以比较 Bun 的 lockb 锁文件","sidebarTitle":"配置 git 比较 Bun 的锁文件","mode":"center","href":"/guides/install/git-diff-bun-lockfile"},{"title":"在 GitHub Actions 中使用 Bun 安装依赖","sidebarTitle":"在 GitHub Actions 中安装 Bun","mode":"center","href":"/guides/install/cicd"}]},{"group":"测试运行器","icon":"flask-conical","pages":[{"title":"使用 Bun 测试运行器运行测试","sidebarTitle":"运行测试","mode":"center","href":"/guides/test/run-tests"},{"title":"使用 Bun 的监听模式运行测试","sidebarTitle":"监听模式","mode":"center","href":"/guides/test/watch-mode"},{"title":"从 Jest 迁移到 Bun 的测试运行器","sidebarTitle":"从 Jest 迁移","mode":"center","href":"/guides/test/migrate-from-jest"},{"title":"在 `bun test` 中使用模拟函数","sidebarTitle":"模拟函数","mode":"center","href":"/guides/test/mock-functions"},{"title":"在 `bun test` 中监视方法","sidebarTitle":"监视方法","mode":"center","href":"/guides/test/spy-on"},{"title":"在 Bun 的测试运行器中设置系统时间","sidebarTitle":"模拟系统时间","mode":"center","href":"/guides/test/mock-clock"},{"title":"在 `bun test` 中使用快照测试","sidebarTitle":"快照测试","mode":"center","href":"/guides/test/snapshot"},{"title":"在 `bun test` 中更新快照","sidebarTitle":"更新快照","mode":"center","href":"/guides/test/update-snapshots"},{"title":"使用 Bun 测试运行器生成代码覆盖率报告","sidebarTitle":"覆盖率报告","mode":"center","href":"/guides/test/coverage"},{"title":"使用 Bun 测试运行器设置代码覆盖率阈值","sidebarTitle":"覆盖率阈值","mode":"center","href":"/guides/test/coverage-threshold"},{"title":"使用通配符模式有选择地并发运行测试","sidebarTitle":"并发测试通配符","mode":"center","href":"/guides/test/concurrent-test-glob"},{"title":"使用 Bun 测试运行器跳过测试","sidebarTitle":"跳过测试","mode":"center","href":"/guides/test/skip-tests"},{"title":"使用 Bun 测试运行器将测试标记为“todo”","sidebarTitle":"待办测试","mode":"center","href":"/guides/test/todo-tests"},{"title":"使用 Bun 测试运行器设置单个测试超时","sidebarTitle":"测试超时","mode":"center","href":"/guides/test/timeout"},{"title":"使用 Bun 测试运行器提前中止","sidebarTitle":"提前中止","mode":"center","href":"/guides/test/bail"},{"title":"使用 Bun 测试运行器多次重新运行测试","sidebarTitle":"重新运行测试","mode":"center","href":"/guides/test/rerun-each"},{"title":"在 Bun 中使用 Testing Library","sidebarTitle":"Testing Library","mode":"center","href":"/guides/test/testing-library"},{"title":"使用 Bun 和 happy-dom 编写浏览器 DOM 测试","sidebarTitle":"DOM 测试","mode":"center","href":"/guides/test/happy-dom"},{"title":"使用 bun test 导入、require 和测试 Svelte 组件","sidebarTitle":"测试 Svelte","mode":"center","href":"/guides/test/svelte-test"}]},{"group":"运行时与调试","icon":"bug","pages":[{"title":"使用 VS Code 扩展调试 Bun","sidebarTitle":"VS Code 调试器","mode":"center","href":"/guides/runtime/vscode-debugger"},{"title":"使用网页调试器调试 Bun","sidebarTitle":"网页调试器","mode":"center","href":"/guides/runtime/web-debugger"},{"title":"使用 V8 堆快照检查内存使用情况","sidebarTitle":"堆快照","mode":"center","href":"/guides/runtime/heap-snapshot"},{"title":"使用 --define 实现构建时常量","sidebarTitle":"构建时常量","mode":"center","href":"/guides/runtime/build-time-constants"},{"title":"定义并替换静态全局变量和常量","sidebarTitle":"定义常量","mode":"center","href":"/guides/runtime/define-constant"},{"title":"在 GitHub Actions 中安装并运行 Bun","sidebarTitle":"GitHub Actions","mode":"center","href":"/guides/runtime/cicd"},{"title":"在 macOS 上为单文件 JavaScript 可执行文件进行代码签名","sidebarTitle":"macOS 上的代码签名","mode":"center","href":"/guides/runtime/codesign-macos-executable"}]},{"group":"模块系统","icon":"box","pages":[{"title":"导入 JSON 文件","sidebarTitle":"导入 JSON","mode":"center","href":"/guides/runtime/import-json"},{"title":"导入 TOML 文件","sidebarTitle":"导入 TOML","mode":"center","href":"/guides/runtime/import-toml"},{"title":"导入 YAML 文件","sidebarTitle":"导入 YAML","mode":"center","href":"/guides/runtime/import-yaml"},{"title":"导入 JSON5 文件","sidebarTitle":"导入 JSON5","mode":"center","href":"/guides/runtime/import-json5"},{"title":"导入 XML 文件","sidebarTitle":"导入 XML","mode":"center","href":"/guides/runtime/import-xml"},{"title":"将 HTML 文件作为文本导入","sidebarTitle":"导入 HTML","mode":"center","href":"/guides/runtime/import-html"},{"title":"获取当前文件的目录","sidebarTitle":"import.meta.dir","mode":"center","href":"/guides/util/import-meta-dir"},{"title":"获取当前文件的文件名","sidebarTitle":"import.meta.file","mode":"center","href":"/guides/util/import-meta-file"},{"title":"获取当前文件的绝对路径","sidebarTitle":"import.meta.path","mode":"center","href":"/guides/util/import-meta-path"},{"title":"检查当前文件是否为入口点","sidebarTitle":"检查入口点","mode":"center","href":"/guides/util/entrypoint"},{"title":"获取当前入口文件的绝对路径","sidebarTitle":"获取入口文件路径","mode":"center","href":"/guides/util/main"}]},{"group":"文件系统","icon":"folder","pages":[{"title":"将文件作为字符串读取","sidebarTitle":"作为字符串读取","mode":"center","href":"/guides/read-file/string"},{"title":"将文件读取到 Buffer","sidebarTitle":"读取到 Buffer","mode":"center","href":"/guides/read-file/buffer"},{"title":"读取文件到 Uint8Array","sidebarTitle":"读取到 Uint8Array","mode":"center","href":"/guides/read-file/uint8array"},{"title":"读取文件到 ArrayBuffer","sidebarTitle":"读取到 ArrayBuffer","mode":"center","href":"/guides/read-file/arraybuffer"},{"title":"读取 JSON 文件","sidebarTitle":"读取 JSON 文件","mode":"center","href":"/guides/read-file/json"},{"title":"获取文件的 MIME 类型","sidebarTitle":"获取 MIME 类型","mode":"center","href":"/guides/read-file/mime"},{"title":"检查文件是否存在","sidebarTitle":"检查文件存在","mode":"center","href":"/guides/read-file/exists"},{"title":"监视目录变化","sidebarTitle":"监视目录","mode":"center","href":"/guides/read-file/watch"},{"title":"以 ReadableStream 读取文件","sidebarTitle":"以流读取","mode":"center","href":"/guides/read-file/stream"},{"title":"将字符串写入文件","sidebarTitle":"写字符串到文件","mode":"center","href":"/guides/write-file/basic"},{"title":"将 Blob 写入文件","sidebarTitle":"写入 Blob","mode":"center","href":"/guides/write-file/blob"},{"title":"将 Response 写入文件","sidebarTitle":"写入响应","mode":"center","href":"/guides/write-file/response"},{"title":"追加内容到文件","sidebarTitle":"追加到文件","mode":"center","href":"/guides/write-file/append"},{"title":"递增写入文件","sidebarTitle":"递增写入","mode":"center","href":"/guides/write-file/filesink"},{"title":"将 ReadableStream 写入文件","sidebarTitle":"写入流","mode":"center","href":"/guides/write-file/stream"},{"title":"写入到标准输出","sidebarTitle":"写入到标准输出","mode":"center","href":"/guides/write-file/stdout"},{"title":"写入文件到标准输出","sidebarTitle":"写文件到标准输出","mode":"center","href":"/guides/write-file/cat"},{"title":"将文件复制到另一个位置","sidebarTitle":"复制文件","mode":"center","href":"/guides/write-file/file-cp"},{"title":"删除文件","sidebarTitle":"删除文件","mode":"center","href":"/guides/write-file/unlink"},{"title":"删除文件","sidebarTitle":"删除文件","mode":"center","href":"/guides/runtime/delete-file"},{"title":"删除目录","sidebarTitle":"删除目录","mode":"center","href":"/guides/runtime/delete-directory"}]},{"group":"实用工具","icon":"wrench","pages":[{"title":"密码哈希","sidebarTitle":"密码哈希","mode":"center","href":"/guides/util/hash-a-password"},{"title":"生成 UUID","sidebarTitle":"生成 UUID","mode":"center","href":"/guides/util/javascript-uuid"},{"title":"编码和解码 base64 数据","sidebarTitle":"Base64 编码","mode":"center","href":"/guides/util/base64"},{"title":"使用 gzip 压缩和解压数据","sidebarTitle":"Gzip 压缩","mode":"center","href":"/guides/util/gzip"},{"title":"使用 DEFLATE 进行数据压缩和解压","sidebarTitle":"DEFLATE 压缩","mode":"center","href":"/guides/util/deflate"},{"title":"转义 HTML 字符串","sidebarTitle":"转义 HTML","mode":"center","href":"/guides/util/escape-html"},{"title":"检查两个对象是否深度相等","sidebarTitle":"深度相等","mode":"center","href":"/guides/util/deep-equals"},{"title":"固定毫秒数的休眠","sidebarTitle":"休眠","mode":"center","href":"/guides/util/sleep"},{"title":"将文件 URL 转换为绝对路径","sidebarTitle":"文件 URL 转路径","mode":"center","href":"/guides/util/file-url-to-path"},{"title":"将绝对路径转换为文件 URL","sidebarTitle":"路径转文件 URL","mode":"center","href":"/guides/util/path-to-file-url"},{"title":"获取可执行二进制文件的路径","sidebarTitle":"查找可执行文件路径","mode":"center","href":"/guides/util/which-path-to-executable-bin"}]},{"group":"HTML 处理","icon":"file-code","pages":[{"title":"使用 HTMLRewriter 提取网页中的链接","sidebarTitle":"使用 HTMLRewriter 提取链接","mode":"center","href":"/guides/html-rewriter/extract-links"},{"title":"提取社交分享图片和开放图谱标签","sidebarTitle":"OpenGraph 标签","mode":"center","href":"/guides/html-rewriter/extract-social-meta"}]},{"group":"二进制数据","icon":"binary","pages":[{"title":"将 ArrayBuffer 转换为字符串","sidebarTitle":"ArrayBuffer 到字符串","mode":"center","href":"/guides/binary/arraybuffer-to-string"},{"title":"将 ArrayBuffer 转换为 Buffer","sidebarTitle":"ArrayBuffer 转 Buffer","mode":"center","href":"/guides/binary/arraybuffer-to-buffer"},{"title":"将 ArrayBuffer 转换为 Blob","sidebarTitle":"ArrayBuffer 转 Blob","mode":"center","href":"/guides/binary/arraybuffer-to-blob"},{"title":"将 ArrayBuffer 转换为数字数组","sidebarTitle":"ArrayBuffer 转数组","mode":"center","href":"/guides/binary/arraybuffer-to-array"},{"title":"将 ArrayBuffer 转换为 Uint8Array","sidebarTitle":"ArrayBuffer 到 Uint8Array","mode":"center","href":"/guides/binary/arraybuffer-to-typedarray"},{"title":"将 Buffer 转换为字符串","sidebarTitle":"Buffer 转字符串","mode":"center","href":"/guides/binary/buffer-to-string"},{"title":"将 Buffer 转换为 ArrayBuffer","sidebarTitle":"Buffer 转 ArrayBuffer","mode":"center","href":"/guides/binary/buffer-to-arraybuffer"},{"title":"将 Buffer 转换为 Blob","sidebarTitle":"Buffer 转 Blob","mode":"center","href":"/guides/binary/buffer-to-blob"},{"title":"将 Buffer 转换为 Uint8Array","sidebarTitle":"Buffer 转 Uint8Array","mode":"center","href":"/guides/binary/buffer-to-typedarray"},{"title":"将 Buffer 转换为 ReadableStream","sidebarTitle":"Buffer 转 ReadableStream","mode":"center","href":"/guides/binary/buffer-to-readablestream"},{"title":"将 Blob 转换为字符串","sidebarTitle":"Blob 转字符串","mode":"center","href":"/guides/binary/blob-to-string"},{"title":"将 Blob 转换为 ArrayBuffer","sidebarTitle":"Blob 转 ArrayBuffer","mode":"center","href":"/guides/binary/blob-to-arraybuffer"},{"title":"将 Blob 转换为 Uint8Array","sidebarTitle":"Blob 转 Uint8Array","mode":"center","href":"/guides/binary/blob-to-typedarray"},{"title":"将 Blob 转换为 DataView","sidebarTitle":"Blob 转 DataView","mode":"center","href":"/guides/binary/blob-to-dataview"},{"title":"将 Blob 转换为 ReadableStream","sidebarTitle":"Blob 转 ReadableStream","mode":"center","href":"/guides/binary/blob-to-stream"},{"title":"将 Uint8Array 转换为字符串","sidebarTitle":"Uint8Array 转字符串","mode":"center","href":"/guides/binary/typedarray-to-string"},{"title":"将 Uint8Array 转换为 ArrayBuffer","sidebarTitle":"Uint8Array 到 ArrayBuffer","mode":"center","href":"/guides/binary/typedarray-to-arraybuffer"},{"title":"将 Uint8Array 转换为 Buffer","sidebarTitle":"Uint8Array 转 Buffer","mode":"center","href":"/guides/binary/typedarray-to-buffer"},{"title":"将 Uint8Array 转换为 Blob","sidebarTitle":"Uint8Array 转 Blob","mode":"center","href":"/guides/binary/typedarray-to-blob"},{"title":"将 Uint8Array 转换为 DataView","sidebarTitle":"Uint8Array 到 DataView","mode":"center","href":"/guides/binary/typedarray-to-dataview"},{"title":"将 Uint8Array 转换为 ReadableStream","sidebarTitle":"Uint8Array 转 ReadableStream","mode":"center","href":"/guides/binary/typedarray-to-readablestream"},{"title":"将 DataView 转换为字符串","sidebarTitle":"DataView 转字符串","mode":"center","href":"/guides/binary/dataview-to-string"}]},{"group":"Streams","icon":"waves","pages":[{"title":"将 ReadableStream 转换为字符串","sidebarTitle":"流转换为字符串","mode":"center","href":"/guides/streams/to-string"},{"title":"将 ReadableStream 转换为 JSON","sidebarTitle":"流转 JSON","mode":"center","href":"/guides/streams/to-json"},{"title":"将 ReadableStream 转换为 Blob","sidebarTitle":"流转换为 Blob","mode":"center","href":"/guides/streams/to-blob"},{"title":"将 ReadableStream 转换为 Buffer","sidebarTitle":"流转 Buffer","mode":"center","href":"/guides/streams/to-buffer"},{"title":"将 ReadableStream 转换为 ArrayBuffer","sidebarTitle":"流到 ArrayBuffer","mode":"center","href":"/guides/streams/to-arraybuffer"},{"title":"将 ReadableStream 转换为 Uint8Array","sidebarTitle":"Stream 转 Uint8Array","mode":"center","href":"/guides/streams/to-typedarray"},{"title":"将 ReadableStream 转换为块数组","sidebarTitle":"流转数组","mode":"center","href":"/guides/streams/to-array"},{"title":"将 Node.js Readable 转换为字符串","sidebarTitle":"Readable 转字符串","mode":"center","href":"/guides/streams/node-readable-to-string"},{"title":"将 Node.js Readable 转换为 JSON","sidebarTitle":"Readable 转 JSON","mode":"center","href":"/guides/streams/node-readable-to-json"},{"title":"将 Node.js Readable 转换为 Blob","sidebarTitle":"Readable 转 Blob","mode":"center","href":"/guides/streams/node-readable-to-blob"},{"title":"将 Node.js Readable 转换为 Uint8Array","sidebarTitle":"Readable 转 Uint8Array","mode":"center","href":"/guides/streams/node-readable-to-uint8array"},{"title":"将 Node.js Readable 转换为 ArrayBuffer","sidebarTitle":"Readable 到 ArrayBuffer","mode":"center","href":"/guides/streams/node-readable-to-arraybuffer"}]}]},{"tab":"参考","icon":"book","href":"https://bun.com/reference"},{"tab":"博客","icon":"newspaper","href":"https://bun.com/blog"},{"tab":"反馈","icon":"lightbulb","pages":[{"title":"反馈","href":"/feedback"}]}]},"basePath":"","title":"指南 - Bun 中文文档","buildId":"ece5007f5547","dynamics":[],"chunks":[]}