Options
All
  • Public
  • Public/Protected
  • All
Menu

Class File

Hierarchy

  • File

Index

Methods

createReadStream

  • createReadStream(): ReadableStream
  • Download this file from B2.

    const file = bucket.file("text.txt");
    file.createReadStream();

    Returns ReadableStream

createWriteStream

  • createWriteStream(): FileUploadStream
  • Upload to this file on B2.

    This works by loading chunks of the stream, upto B2.partSize, into memory. If the stream has less than or equal to that many bytes, a single-part upload will be attempted.

    Otherwise, a multi-part upload will be attempted by loading up-to b2.partSize bytes of the stream into memory at a time.

    const file = bucket.file("example");
    const stream = file.createWriteStream();
    stream.on("error", (err) => {
      // handle the error
      // note that retries are automatically attempted before errors are
      // thrown for most potentially recoverable errors, as per the B2 docs.
    })
    stream.on("finish", (err) => {
      // upload done, the file instance has been updated to reflect this
    })
    res.body.pipe(stream);

    Returns FileUploadStream

getBucketId

  • getBucketId(): Promise<string>
  • Returns Promise<string>

getBucketName

  • getBucketName(): Promise<string>
  • Returns Promise<string>

getFileId

  • getFileId(): Promise<null | string>

getFileName

  • getFileName(): Promise<string>
  • Returns Promise<string>

stat

Generated using TypeDoc