温馨提示:本站仅提供公开网络链接索引服务,不存储、不篡改任何第三方内容,所有内容版权归原作者所有
AI智能索引来源:http://www.bun.com/reference/bun/BunFile/slice
点击访问原文链接

BunFile.slice method | Bun module | Bun

BunFile.slice method | Bun module | BunBuildDocsReferenceGuidesBlogDiscord/Bun/BunFile/sliceMslice

Search the reference...

/

BuildDocsReferenceGuidesBlogDiscord/Bun/BunFile/sliceMslice

method

BunFile.slice 0, () will be slower on macOS" data-algolia-static="false" data-algolia-merged="false" data-type="Method">slice(begin?: number,end?: number,contentType?: string): BunFile;

Offset any operation on the file starting at begin and ending at end. end is relative to 0

Similar to TypedArray.subarray. Does not copy the file, open the file, or modify the file.

If begin > 0, () will be slower on macOS

@param begin

start offset in bytes

@param end

absolute offset in bytes (relative to 0)

@param contentType

MIME type for the new BunFile

slice(begin?: number,contentType?: string): BunFile;

Offset any operation on the file starting at begin

Similar to TypedArray.subarray. Does not copy the file, open the file, or modify the file.

If begin > 0, Bun.write() will be slower on macOS

@param begin

start offset in bytes

@param contentType

MIME type for the new BunFile

slice(contentType?: string): BunFile;

Slice the file from the beginning to the end, optionally with a new MIME type.

@param contentType

MIME type for the new BunFile

Referenced typesinterface BunFile

Blob powered by the fastest system calls available for operating on files.

This Blob is lazy. That means it won't do any work until you read from it.

size will not be valid until the contents of the file are read at least once.type is auto-set based on the file extension when possible
const file = Bun.file("./hello.json");
console.log(file.type); // "application/json"
console.log(await file.text()); // '{"hello":"world"}'
lastModified: number

A UNIX timestamp indicating when the file was last modified.

readonly name?: string

The name or path of the file, as specified in the constructor.

readonly size: numberreadonly type: stringarrayBuffer(): PromiseArrayBuffer>;

Returns a promise that resolves to the contents of the blob as an ArrayBuffer

bytes(): PromiseUint8ArrayArrayBufferLike>>;bytes(): PromiseUint8ArrayArrayBuffer>>;

Returns a promise that resolves to the contents of the blob as a Uint8Array (array of bytes) its the same as new Uint8Array(await blob.arrayBuffer())

delete(): Promisevoid>;

Deletes the file (same as unlink)

exists(): Promiseboolean>;

Does the file exist?

This returns true for regular files and FIFOs. It returns false for directories. Note that a race condition can occur where the file is deleted or renamed after this is called but before you open it.

This does a system call to check if the file exists, which can be slow.

If using this in an HTTP server, it's faster to instead use return new Response(Bun.file(path)) and then an error handler to handle exceptions.

Instead of checking for a file's existence and then performing the operation, it is faster to just perform the operation and handle the error.

For empty Blob, this always returns true.

formData(): PromiseFormData>;

Read the data from the blob as a FormData object.

This first decodes the data from UTF-8, then parses it as a multipart/form-data body or a application/x-www-form-urlencoded body.

The type property of the blob is used to determine the format of the body.

This is a non-standard addition to the Blob API, to make it conform more closely to the BodyMixin API.

image(options?: ConstructorOptions): Image;

Wrap this blob in a Bun.Image pipeline. Equivalent to new Bun.Image(this, options) — the constructor is synchronous (the underlying read happens lazily when an Image terminal is awaited), so this works on Bun.file(), Bun.s3(), fd-backed and in-memory blobs alike:

await Bun.file("photo.jpg").image().resize(400).webp().write("thumb.webp");
json(): Promiseany>;

Read the data from the blob as a JSON object.

This first decodes the data from UTF-8, then parses it as JSON.

0, () will be slower on macOS" data-algolia-static="false" data-algolia-merged="false" data-type="Method">slice(begin?: number,end?: number,contentType?: string): BunFile;

Offset any operation on the file starting at begin and ending at end. end is relative to 0

Similar to TypedArray.subarray. Does not copy the file, open the file, or modify the file.

If begin > 0, () will be slower on macOS

@param begin

start offset in bytes

@param end

absolute offset in bytes (relative to 0)

@param contentType

MIME type for the new BunFile

slice(begin?: number,contentType?: string): BunFile;

Offset any operation on the file starting at begin

Similar to TypedArray.subarray. Does not copy the file, open the file, or modify the file.

If begin > 0, Bun.write() will be slower on macOS

@param begin

start offset in bytes

@param contentType

MIME type for the new BunFile

slice(contentType?: string): BunFile;

Slice the file from the beginning to the end, optionally with a new MIME type.

@param contentType

MIME type for the new BunFile

stat(): PromiseStats>;

Provides useful information about the file.

stream(): ReadableStreamUint8ArrayArrayBufferLike>>;stream(): ReadableStreamUint8ArrayArrayBuffer>>;

Returns a readable stream of the blob's contents

text(): Promisestring>;

Returns a promise that resolves to the contents of the blob as a string

unlink(): Promisevoid>;

Deletes the file.

write(data: string | ArrayBuffer | SharedArrayBuffer | BunFile | Request | Response | ArrayBufferViewArrayBufferLike>,options?: { highWaterMark: number }): Promisenumber>;

Write data to the file. This is equivalent to using Bun.write with a BunFile.

@param data

The data to write.

@param options

The options to use for the write.

writer(options?: { highWaterMark: number }): FileSink;

Incremental writer for files and pipes.

Resources

ReferenceDocsGuidesDiscordMerch StoreGitHubBlog 

Toolkit

RuntimePackage managerTest runnerBundlerPackage runner

Project

Bun 1.0Bun 1.1Bun 1.2Bun 1.3RoadmapContributingLicense

Baked with ❤️ in San Francisco

We're hiring →

BunFile.slice method | Bun module | Bun,AI智能索引,全网链接索引,智能导航,网页索引

    API documentation for method bun.BunFile.slice | Bun