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

S3File.slice method | Bun module | Bun

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

Search the reference...

/

BuildDocsReferenceGuidesBlogDiscord/Bun/S3File/sliceMslice

method

S3File.sliceslice(begin?: number,end?: number,contentType?: string): S3File;

Creates a new S3File representing a slice of the original file. Uses HTTP Range headers for efficient partial downloads.

@param begin

Starting byte offset

@param end

Ending byte offset (exclusive)

@param contentType

Optional MIME type for the slice

@returns

A new S3File representing the specified range

// Reading file header
const header = file.slice(0, 1024);
const headerText = await header.text();
slice(begin?: number,contentType?: string): S3File;slice(contentType?: string): S3File;Referenced typesinterface S3File

Represents a file in an S3-compatible storage service. Extends the Blob interface for compatibility with web APIs.

readonly bucket?: string

The bucket name containing the file.

const file = s3.file("s3:http://my-bucket/file.txt");
console.log(file.bucket); // "my-bucket"
readonly name?: string

The name or path of the file in the bucket.

const file = s3.file("folder/image.jpg");
console.log(file.name); // "folder/image.jpg"
readonly readable: ReadableStreamUint8ArrayArrayBuffer>>

Gets a readable stream of the file's content. Useful for processing large files without loading them entirely into memory.

// Basic streaming read
const stream = file.stream();
for await (const chunk of stream) {
console.log('Received chunk:', chunk);
}
readonly size: numberreadonly type: stringunlink: () => Promisevoid>

Alias for delete() method. Provided for compatibility with Node.js fs API naming.

await file.unlink();
arrayBuffer(): 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 from S3.

@returns

Promise that resolves when deletion is complete

// Basic deletion
await file.delete();
exists(): Promiseboolean>;

Checks if the file exists in S3. Uses HTTP HEAD request to efficiently check existence without downloading.

@returns

Promise resolving to true if file exists, false otherwise

// Basic existence check
if (await file.exists()) {
console.log("File exists in S3");
}
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.

presign(options?: S3FilePresignOptions): string;

Generates a presigned URL for the file. Allows temporary access to the file without exposing credentials.

@param options

Configuration for the presigned URL

@returns

Presigned URL string

// Basic download URL
const url = file.presign({
expiresIn: 3600 // 1 hour
});
slice(begin?: number,end?: number,contentType?: string): S3File;

Creates a new S3File representing a slice of the original file. Uses HTTP Range headers for efficient partial downloads.

@param begin

Starting byte offset

@param end

Ending byte offset (exclusive)

@param contentType

Optional MIME type for the slice

@returns

A new S3File representing the specified range

// Reading file header
const header = file.slice(0, 1024);
const headerText = await header.text();
slice(begin?: number,contentType?: string): S3File;slice(contentType?: string): S3File;stat(): PromiseS3Stats>;

Get the stat of a file in an S3-compatible storage service.

@returns

Promise resolving to S3Stat

stream(): ReadableStreamUint8ArrayArrayBuffer>>;text(): Promisestring>;

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

write(data: string | ArrayBuffer | SharedArrayBuffer | Blob | BunFile | Request | Response | ArrayBufferViewArrayBufferLike> | S3File | Archive,options?: S3Options): Promisenumber>;

Uploads data to S3. Supports various input types and automatically handles large files.

@param data

The data to upload

@param options

Upload configuration options

@returns

Promise resolving to number of bytes written

// Writing string data
await file.write("Hello World", {
type: "text/plain"
});
writer(options?: S3Options): NetworkSink;

Creates a writable stream for uploading data. Suitable for large files as it uses multipart upload.

@param options

Configuration for the upload

@returns

A NetworkSink for writing data

// Basic streaming write
const writer = file.writer({
type: "application/json"
});
writer.write('{"hello": ');
writer.write('"world"}');
await writer.end();

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 →

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

    API documentation for method bun.S3File.slice | Bun