bun v0.0.76 #138
Jarred-Sumner
announced in
Announcements
bun v0.0.76
#138
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
To upgrade:
What's new
bun-types
npm package. A PR for @types/bun is waiting review (feel free to nudge them).Bun.serve()
is a fast HTTP & HTTPS server that supports theRequest
andResponse
Web APIs. The server is a fork of uWebSocketsBun.write()
– one API for writing files, pipes, and copying files leveraging the fastest system calls available for the input & platform. It uses theBlob
Web API.Bun.mmap(path)
lets you read files as a live-updatingUint8Array
via the mmap(2) syscall. Thank you @evanwashere!!Bun.hash(bufferOrString)
exposes fast non-cryptographic hashing functions. Useful for things likeETag
, not for passwords.Bun.allocUnsafe(length)
creates a new Uint8Array ~3.5x faster than new Uint8Array, but it is not zero-initialized. This is similar to Node'sBuffer.allocUnsafe
, though without the memory pool currentlyURL
examples
folderfs.read()
andfs.write()
and some more tests for fsResponse.redirect()
,Response.json()
, andResponse.error()
have been addedimport.meta.url
is now a file:// url stringBun.resolve
andBun.resolveSync
let you resolve the same asimport
does. It throws aResolveError
on failure (same asimport
)Bun.stderr
andBun.stdout
now return aBlob
SharedArrayBuffer
is now enabled (thanks @evanwashere!)New Web APIs in bun.js
Going forward, Bun will first try to rely on WebKit/Safari's implementations of Web APIs rather than writing new ones. This will improve Web API compatibility while reducing bun's scope, without compromising performance
These Web APIs are now available in bun.js and powered by Safari's implementation:
URL
URLSearchParams
ErrorEvent
Event
EventTarget
DOMException
Headers
uses WebKit's implementation now instead of a custom oneAbortSignal
(not wired up to fetch or fs yet, it exists but not very useful)AbortController
Also added:
reportError
(does not dispatch an"error"
event yet)Additionally, all the builtin constructors in bun now have a
.prototype
property (this was missing before)Bun.serve
- fast HTTP serverFor a hello world HTTP server that writes "bun!",
Bun.serve
serves about 2.5x more requests per second than node.js on Linux:Bigger is better
Code
Bun:
Node:
Usage
Two ways to start an HTTP server with bun.js:
export default
an object with afetch
functionIf the file used to start bun has a default export with a
fetch
function, it will start the http server.fetch
receives aRequest
object and must return either aResponse
or aPromise<Response>
. In a future version, it might have an additional arguments for things like cookies.Bun.serve
starts the http server explicitlyError handling
For error handling, you get an
error
function.If
development: true
anderror
is not defined or doesn't return aResponse
, you will get an exception page with a stack trace:It will hopefully make it easier to debug issues with bun until bun gets debugger support. This error page is based on what
bun dev
does.If the error function returns a
Response
, it will be served insteadIf the
error
function itself throws anddevelopment
isfalse
, a generic 500 page will be shownCurrently, there is no way to stop the HTTP server once started 😅, but that will be added in a future version.
The interface for
Bun.serve
is based on what Cloudflare Workers does.Bun.write() – optimizing I/O
Bun.write
lets you write, copy or pipe files automatically using the fastest system calls compatible with the input and platform.All this complexity is handled by a single function.
Bug fixes
require
to produce incorrect output depending on how the module was usedbun dev
related to HMR & websockets - Jarred-Sumner/bun@daeede2fs.openSync
now supportsmode
andflags
- Jarred-Sumner/bun@c73fcb0fs.read
andfs.write
were incorrectly returning the output offs/promises
versions, this is fixedfs
function received a TypedArray as input. - Jarred-Sumner/bun@614f64b. This also improves performance of sending array buffers to native a littleResponse
's constructor previously readstatusCode
instead ofstatus
. This was incorrect and has been fixed.fs.stat
reported incorrect information on macOS x64improve performance of accessing
Bun.Transpiler
andBun.unsafe
29a759aThis discussion was created from the release bun v0.0.76.
Beta Was this translation helpful? Give feedback.
All reactions