ReadonlyidUnique identifier for this bucket.
ReadonlyinfoFull bucket metadata as returned by the B2 API.
ReadonlynameHuman-readable bucket name.
Adds (or replaces, matched by fileNamePrefix) a single lifecycle rule
while leaving any other rules untouched.
Matching on prefix mirrors B2's own data model: each unique prefix can
have at most one rule, and a b2_update_bucket call that contains two
rules with the same prefix is rejected. The helper enforces this for
the caller.
The lifecycle rule to add or replace.
The updated bucket metadata.
Adds (or replaces by replicationRuleName) a single replication rule
on this bucket while leaving any other rules, the source key, and the
destination key mapping untouched.
When this is the very first source-side rule, sourceApplicationKeyId
must be supplied to seed asReplicationSource.sourceApplicationKeyId;
for subsequent calls the existing source key is reused unless the
caller explicitly overrides it.
The replication rule to add or replace.
Optionaloptions: { sourceApplicationKeyId?: ApplicationKeyId }Optional source application key ID override (or seed when no source side exists yet).
The updated bucket metadata.
Cancels an in-progress large file upload so the partial parts are not retained or billed. The most common reason to call this is to clean up abandoned multipart uploads surfaced by listUnfinishedLargeFiles.
The unique identifier of the unfinished large file to cancel.
Metadata about the cancelled large file.
Creates a server-side copy of a file within or across buckets.
Copy configuration including source file ID and destination name.
OptionalcontentType?: stringOverride content type (only with REPLACE metadata directive).
OptionaldestinationBucketId?: BucketIdTarget bucket ID. Defaults to this bucket if omitted.
OptionalfileInfo?: Record<string, string>Override file info (only with REPLACE metadata directive).
Destination file name in the target bucket.
OptionalmetadataDirective?: MetadataDirectiveWhether to copy or replace file metadata.
OptionalserverSideEncryption?: EncryptionSettingServer-side encryption for the destination file.
File ID of the source file to copy.
Metadata for the newly created file version.
Copies a file via the server-side multipart protocol. Each part is copied
by reference through b2_copy_part; data never traverses the client. Falls
back to a single copyFile call when the source fits within a single part.
Copy parameters including source file ID, destination name, part size, and concurrency.
Optionalconcurrency?: numberMaximum number of parts copied in parallel. Defaults to the SDK-wide transfer concurrency.
OptionalcontentType?: stringOverride content type for the destination.
OptionaldestinationBucketId?: BucketIdTarget bucket ID. Defaults to this bucket if omitted.
OptionaldestinationServerSideEncryption?: EncryptionSettingServer-side encryption for the destination file.
OptionalfileInfo?: Record<string, string>Custom file info for the destination.
Destination file name in the target bucket.
OptionalpartSize?: numberPart size in bytes. Defaults to the account's recommended part size.
Optionalsignal?: AbortSignalOptional abort signal. Aborting cancels any remaining parts and
triggers a best-effort cancelLargeFile on the unfinished upload.
File ID of the source file to copy.
OptionalsourceServerSideEncryption?: EncryptionSettingSSE-C settings for the source if it was uploaded with SSE-C.
Metadata for the newly created destination file version.
Permanently deletes this bucket. The bucket must be empty (no file versions).
The deleted bucket metadata.
Async generator that streams every file version in the bucket (optionally
filtered by prefix) and deletes each one. Yields a DeleteAllEvent
per file version. With dryRun: true, no deletes are performed but skip
events are still emitted.
Optionaloptions: { dryRun?: boolean; pageSize?: number; prefix?: string }Optional prefix filter, page size, and dry-run flag.
OptionaldryRun?: booleanIf true, yield skip events without actually deleting anything.
OptionalpageSize?: numberNumber of file versions fetched per API page (default 1000).
Optionalprefix?: stringOnly delete file versions whose names start with this prefix.
An async generator of per-file events.
Permanently deletes a specific file version. Both file name and file ID are required.
If the file is under Object Lock retention, B2 will reject the
delete: compliance-mode files cannot be deleted until the retention
expires; governance-mode files require bypassGovernance: true
AND a calling key with the bypassGovernance capability. Files on
legal hold cannot be deleted by anyone until the hold is removed.
The file path of the version to delete.
The unique identifier of the file version to delete.
Optionaloptions: { bypassGovernance?: boolean }Optional flag for bypassing governance retention.
Deletes many file versions with bounded concurrency. Errors from individual deletes are collected and returned rather than thrown, so partial success does not abort the run.
When options.signal is supplied and aborted, in-flight deletes
complete (they're already on the wire), but no new deletes start
after the abort fires. Subsequent targets are short-circuited to an
error entry so the result tally reflects what actually happened.
File versions to delete.
Optionaloptions: { concurrency?: number; signal?: AbortSignal }Optional concurrency override and abort signal. Concurrency defaults to the SDK-wide bulk-metadata setting (currently 10, higher than transfer concurrency because each task is a single tiny API round-trip).
A summary of successes and per-target errors.
Downloads a file from this bucket by name. Pass method: 'HEAD' in
options to fetch only the response headers (file metadata) without
streaming the body.
The file name (path) to download.
Optionaloptions: DownloadCallOptionsOptional method, range, SSE-C decryption, response-header overrides, and abort signal.
The download result containing response headers and a readable body stream.
Returns the current default Object Lock retention policy for new uploads to this bucket, refetched from B2.
The default BucketRetentionPolicy (which may be
{ mode: 'none', period: null } when Object Lock is enabled on the
bucket but no default is set).
Gets a download authorization token scoped to a file name prefix in this bucket.
Only authorize downloads of files starting with this prefix.
How long the authorization is valid (1-604800 seconds).
The download authorization response containing a time-limited token.
Looks up the latest visible version of a file by name.
Uses listFileNames under the hood; returns null when the file does not
exist or its latest version is a hide marker.
The exact file path to look up.
The latest FileVersion, or null if not found.
Returns the current lifecycle rules for this bucket, refetched from B2.
The current array of LifecycleRules.
Gets the event notification rules configured for this bucket.
The current notification rules for this bucket.
Returns the current cross-region replication configuration, refetched from B2.
Use this when you need to read replication state without composing a write. For add/remove flows the helper methods below handle the refresh-then-set sequence for you.
The current ReplicationConfiguration.
Fetches the response headers (file metadata) for a file via HTTP HEAD. Returns a body-less result so callers never have to drain the (logically empty) HEAD body themselves.
Use this for metadata-only checks like "does this file exist", "what is its current SHA-1", "what is its Content-Length". For full file retrieval use Bucket.download.
The file name (path) to inspect.
Optionaloptions: HeadCallOptionsOptional range, SSE-C decryption, response-header
overrides, and abort signal. Same shape as Bucket.download's
options minus method (always HEAD) and onProgress (no body).
Parsed download headers (content type, SHA-1, file info, etc.).
Hides a file by creating a hide marker. The file remains in version history but is no longer visible in listFileNames.
The file path to hide.
Metadata for the newly created hide marker.
Lists file names in this bucket (most recent versions only).
Optionaloptions: {Optional filtering and pagination settings.
Optionaldelimiter?: stringDelimiter for virtual directory grouping (typically "/").
OptionalpageSize?: numberMaximum number of files to return per request (1-10000).
Forwarded to the raw API's maxFileCount parameter.
Optionalprefix?: stringOnly list files with names starting with this prefix.
OptionalstartFileName?: stringStart listing after this file name (for pagination).
A page of file versions with an optional continuation token.
Lists all file versions in this bucket, including hidden files.
Optionaloptions: {Optional filtering and pagination settings.
Optionaldelimiter?: stringDelimiter for virtual directory grouping.
OptionalpageSize?: numberMaximum number of file versions to return per request (1-10000).
Forwarded to the raw API's maxFileCount parameter.
Optionalprefix?: stringOnly list files with names starting with this prefix.
OptionalstartFileId?: FileIdStart listing after this file ID (for pagination within a file name).
OptionalstartFileName?: stringStart listing after this file name (for pagination).
A page of file versions with an optional continuation token.
Lists large files in this bucket that were started but never finished or
cancelled. Wraps b2_list_unfinished_large_files.
Optionaloptions: { namePrefix?: string; pageSize?: number; startFileId?: LargeFileId }Optional pagination filters.
OptionalnamePrefix?: stringRestrict results to files whose name starts with this prefix.
OptionalpageSize?: numberMaximum number of files to return per request (1-100). Forwarded
to the raw API's maxFileCount parameter.
OptionalstartFileId?: LargeFileIdStart listing after this file ID (for pagination).
The page of unfinished large files plus a continuation token.
Async iterator that yields the latest visible version of every file in
the bucket, automatically handling pagination via listFileNames.
Hidden files (those whose latest version is a hide marker) are NOT yielded by this iterator. Use paginateFileVersions when you need full version history.
Optionaloptions: { delimiter?: string; prefix?: string } & PaginatorOptionsFilter + pagination + abort options. pageSize is
forwarded to b2_list_file_names's maxFileCount (default 1000,
B2-capped at 10000).
Optionaldelimiter?: stringDelimiter for virtual directory grouping (typically '/').
Optionalprefix?: stringOnly yield files whose names start with this prefix.
An async iterable of FileVersion entries.
Async iterator that yields every version of every file in the bucket,
including hidden files and historical versions, automatically handling
pagination via listFileVersions.
The two-cursor (nextFileName, nextFileId) continuation that the raw
endpoint exposes is threaded internally; callers iterate flat.
Optionaloptions: { delimiter?: string; prefix?: string } & PaginatorOptionsFilter + pagination + abort options.
Optionaldelimiter?: stringDelimiter for virtual directory grouping.
Optionalprefix?: stringOnly yield versions whose names start with this prefix.
An async iterable of FileVersion entries.
Async iterator that yields every uploaded part for a specific large
file, automatically handling pagination via listParts.
The unfinished large file to enumerate parts of.
Optionaloptions: PaginatorOptionsPagination + abort options. pageSize is B2-capped
at 1000 for this endpoint; the default is 1000.
An async iterable of PartInfo entries.
Async iterator that yields every unfinished large file in the bucket,
automatically handling pagination via listUnfinishedLargeFiles.
Useful for janitorial scripts that want to inspect or cancel abandoned multipart uploads (typically followed by cancelLargeFile on the underlying raw client).
Optionaloptions: { namePrefix?: string } & PaginatorOptionsFilter + pagination + abort options. pageSize is
B2-capped at 100 for this endpoint.
OptionalnamePrefix?: stringOnly yield large files whose names start with this prefix.
An async iterable of unfinished-large-file metadata entries.
Removes a single lifecycle rule by prefix. No-ops cleanly when the rule is not present.
The prefix of the rule to remove.
The updated bucket metadata.
Removes a single replication rule by name. No-ops cleanly when the rule is not present (returns the unchanged-but-revision-bumped bucket info).
Name of the rule to remove.
The updated bucket metadata.
Sets (or clears, by passing { mode: 'none', period: null }) the
default Object Lock retention policy applied to new uploads.
Object Lock must already be enabled on the bucket. Buckets created
without fileLockEnabled: true cannot accept a default retention
policy and B2 will reject this call.
The new default retention policy.
The updated bucket metadata.
Replaces this bucket's lifecycle rules in their entirety.
The new rule set. Pass [] to remove all lifecycle
automation.
The updated bucket metadata.
Replaces the event notification rules for this bucket.
The new set of notification rules to apply.
The updated notification rules for this bucket.
Replaces this bucket's complete replication configuration.
The new configuration. Pass an empty source/destination
pair ({ asReplicationSource: null, asReplicationDestination: null })
to clear replication entirely.
The updated bucket metadata.
Removes the latest hide marker for a file, restoring visibility of the
previous upload. Returns the deleted hide marker, or null if there was
no hide marker to remove (file is already visible or does not exist).
The file path to unhide.
The deleted hide marker version, or null if nothing was hidden.
Updates bucket settings such as type, CORS, lifecycle rules, and encryption.
Fields to update. Omitted fields are left unchanged.
OptionalbucketInfo?: Record<string, string>Replace custom bucket metadata.
OptionalbucketType?: BucketTypeChange the bucket access level.
OptionalcorsRules?: CorsRule[]Replace CORS rules.
OptionaldefaultRetention?: BucketRetentionPolicyChange default file retention policy.
OptionaldefaultServerSideEncryption?: EncryptionSettingChange default server-side encryption.
OptionalifRevisionIs?: numberOptimistic locking: only update if the bucket revision matches.
OptionallifecycleRules?: LifecycleRule[]Replace lifecycle rules.
OptionalreplicationConfiguration?: ReplicationConfigurationUpdate replication configuration.
Updated bucket metadata.
Updates the legal hold status for a specific file version. Requires file lock on the bucket.
The file path of the version to update.
The unique identifier of the file version.
The new legal hold status to apply.
The updated legal hold metadata.
Updates the file retention policy for a specific file version. Requires file lock on the bucket.
The file path of the version to update.
The unique identifier of the file version.
The new retention policy to apply.
Optionaloptions: { bypassGovernance?: boolean }Optional flags. Set bypassGovernance: true to shorten governance-mode retention.
The updated file retention metadata.
Uploads a file to this bucket. Automatically uses multipart upload for files larger than the recommended part size.
Upload configuration including file name, source data, and optional settings.
Optionalconcurrency?: numberNumber of concurrent part uploads for large files.
OptionalcontentType?: stringMIME type. Defaults to "b2/x-auto" (auto-detected by B2).
OptionalfileInfo?: Record<string, string>Custom key-value metadata stored with the file.
Destination file name (path) in the bucket.
OptionalfileRetention?: FileRetentionValueFile retention policy (requires file lock on the bucket).
OptionallastModifiedMillis?: numberLast-modified timestamp in milliseconds since epoch.
OptionallegalHold?: LegalHoldValueLegal hold status for the file.
OptionalonProgress?: ProgressListenerCallback invoked with upload progress events.
OptionalpartSize?: numberPart size override for multipart uploads, in bytes.
Optionalresume?: booleanResume an unfinished multipart upload for this file name when one
exists. Only consulted on the large-file path (source size
greater than recommendedPartSize). On the small-file path this
option is silently ignored. Sliceable sources only — StreamSource
rejects resume because it can't replay parts.
OptionalresumeFileId?: LargeFileIdResume into a specific large-file ID. Overrides the resume
discovery path. The local partSize must match the server-side
plan.
OptionalserverSideEncryption?: EncryptionSettingServer-side encryption settings.
Optionalsignal?: AbortSignalAbort signal for cancelling the upload.
Data source to upload. Use BufferSource, BlobSource, or StreamSource.
Metadata for the uploaded file version.
Handle to a B2 bucket providing upload, download, listing, and management operations.
Obtained via B2Client.createBucket, B2Client.listBuckets, or B2Client.getBucket.
Example