Package version:

A ShareFileClient represents a URL to an Azure Storage file.

Hierarchy

  • StorageClient
    • ShareFileClient

Constructors

Properties

accountName: string
storageClientContext: StorageClient

StorageClient is a reference to protocol layer operations entry, which is generated by AutoRest generator.

url: string

URL string value.

Accessors

Methods

  • Removes the file from the storage account. When a file is successfully deleted, it is immediately removed from the storage account's index and is no longer accessible to clients. The file's data is later removed from the service during garbage collection.

    Delete File will fail with status code 409 (Conflict) and error code SharingViolation if the file is open on an SMB client.

    Delete File is not supported on a share snapshot, which is a read-only copy of a share. An attempt to perform this operation on a share snapshot will fail with 400 (InvalidQueryParameterValue)

    Parameters

    Returns Promise<FileDeleteResponse>

    Response data for the File Delete operation.

  • Reads or downloads a file from the system, including its metadata and properties.

    • In Node.js, data returns in a Readable stream readableStreamBody
    • In browsers, data returns in a promise contentAsBlob

    Parameters

    • offset: number = 0

      From which position of the file to download, greater than or equal to 0

    • Optionalcount: number

      How much data to be downloaded, greater than 0. Will download to the end when undefined

    • options: FileDownloadOptions = {}

      Options to File Download operation.

    Returns Promise<FileDownloadResponseModel>

    Response data for the File Download operation.

    Example usage (Node.js):

    // Download a file to a string
    const downloadFileResponse = await fileClient.download();
    console.log(
    "Downloaded file content:",
    (await streamToBuffer(downloadFileResponse.readableStreamBody)).toString()}
    );

    // A helper method used to read a Node.js readable stream into string
    async function streamToBuffer(readableStream) {
    return new Promise((resolve, reject) => {
    const chunks = [];
    readableStream.on("data", (data) => {
    chunks.push(typeof data === "string" ? Buffer.from(data) : data);
    });
    readableStream.on("end", () => {
    resolve(Buffer.concat(chunks));
    });
    readableStream.on("error", reject);
    });
    }

    Example usage (browsers):

    // Download a file to a string
    const downloadFileResponse = await fileClient.download(0);
    console.log(
    "Downloaded file content:",
    await blobToString(await downloadFileResponse.blobBody)}
    );

    // A helper method used to convert a browser Blob into string.
    export async function blobToString(blob: Blob): Promise<string> {
    const fileReader = new FileReader();
    return new Promise<string>((resolve, reject) => {
    fileReader.onloadend = (ev: any) => {
    resolve(ev.target!.result);
    };
    fileReader.onerror = reject;
    fileReader.readAsText(blob);
    });
    }
  • ONLY AVAILABLE IN NODE.JS RUNTIME.

    Downloads an Azure file in parallel to a buffer. Offset and count are optional, pass 0 for both to download the entire file.

    Warning: Buffers can only support files up to about one gigabyte on 32-bit systems or about two gigabytes on 64-bit systems due to limitations of Node.js/V8. For files larger than this size, consider downloadToFile.

    Parameters

    • buffer: Buffer

      Buffer to be fill, must have length larger than count

    • Optionaloffset: number

      From which position of the Azure File to download

    • Optionalcount: number

      How much data to be downloaded. Will download to the end when passing undefined

    • Optionaloptions: FileDownloadToBufferOptions

    Returns Promise<Buffer>

  • ONLY AVAILABLE IN NODE.JS RUNTIME

    Downloads an Azure file in parallel to a buffer. Offset and count are optional, pass 0 for both to download the entire file

    Warning: Buffers can only support files up to about one gigabyte on 32-bit systems or about two gigabytes on 64-bit systems due to limitations of Node.js/V8. For files larger than this size, consider downloadToFile.

    Parameters

    • Optionaloffset: number

      From which position of the Azure file to download

    • Optionalcount: number

      How much data to be downloaded. Will download to the end when passing undefined

    • Optionaloptions: FileDownloadToBufferOptions

    Returns Promise<Buffer>

  • ONLY AVAILABLE IN NODE.JS RUNTIME.

    Downloads an Azure Blob to a local file. Fails if the the given file path already exits. Offset and count are optional, pass 0 and undefined respectively to download the entire blob.

    Parameters

    • filePath: string
    • offset: number = 0

      From which position of the block blob to download.

    • Optionalcount: number

      How much data to be downloaded. Will download to the end when passing undefined.

    • options: FileDownloadOptions = {}

      Options to Blob download options.

    Returns Promise<FileDownloadResponseModel>

    The response data for blob download operation, but with readableStreamBody set to undefined since its content is already read and written into a local file at the specified path.

  • Returns true if the specified file exists; false otherwise.

    NOTE: use this function with care since an existing file might be deleted by other clients or applications. Vice versa new files might be added by other clients or applications after this function completes.

    Parameters

    Returns Promise<boolean>

  • Renames a file. This API only supports renaming a file in the same share.

    Parameters

    • destinationPath: string

      Specifies the destination path to rename to. The path will be encoded to put into a URL to specify the destination.

    • options: FileRenameOptions = {}

      Options for the renaming operation.

    Returns Promise<{
        destinationFileClient: ShareFileClient;
        fileRenameResponse: FileRenameResponse;
    }>

    Response data for the file renaming operation.

    Example usage:


    // Rename the file
    await fileClient.rename(destinationPath);
    console.log("Renamed file successfully!");
  • Copies a blob or file to a destination file within the storage account.

    Parameters

    • copySource: string

      Specifies the URL of the source file or blob, up to 2 KB in length. To copy a file to another file within the same storage account, you may use Shared Key to authenticate the source file. If you are copying a file from another storage account, or if you are copying a blob from the same storage account or another storage account, then you must authenticate the source file or blob using a shared access signature. If the source is a public blob, no authentication is required to perform the copy operation. A file in a share snapshot can also be specified as a copy source.

    • options: FileStartCopyOptions = {}

      Options to File Start Copy operation.

    Returns Promise<FileStartCopyResponse>

  • Creates a new Azure File or replaces an existing Azure File, and then uploads a Buffer(Node)/Blob/ArrayBuffer/ArrayBufferView to it.

    Parameters

    Returns Promise<void>

  • ONLY AVAILABLE IN NODE.JS RUNTIME.

    Creates a new Azure File or replaces an existing Azure File, and then uploads a local file to it.

    Parameters

    Returns Promise<void>

  • Upload a range of bytes to a file. This operation can only be called on an existing file. It won't change the size, properties or metadata of the file. Both the start and count of the range must be specified. The range can be up to 4 MB in size.

    Parameters

    • body: HttpRequestBody

      Blob, string, ArrayBuffer, ArrayBufferView or a function which returns a new Readable stream whose offset is from data source beginning.

    • offset: number

      Offset position of the destination Azure File to upload.

    • contentLength: number

      Length of body in bytes. Use Buffer.byteLength() to calculate body length for a string including non non-Base64/Hex-encoded characters.

    • options: FileUploadRangeOptions = {}

      Options to File Upload Range operation.

    Returns Promise<FileUploadRangeResponse>

    Response data for the File Upload Range operation.

    Example usage:

    const content = "Hello world!";

    // Create the file
    await fileClient.create(content.length);
    console.log("Created file successfully!");

    // Then upload data to the file
    await fileClient.uploadRange(content, 0, content.length);
    console.log("Updated file successfully!")
  • Upload a range of bytes to a file where the contents are read from a another file's URL. The range can be up to 4 MB in size.

    Parameters

    • sourceURL: string

      Specify a URL to the copy source, Shared Access Signature(SAS) maybe needed for authentication.

    • sourceOffset: number

      The source offset to copy from. Pass 0 to copy from the beginning of source file.

    • destOffset: number

      Offset of destination file.

    • count: number

      Number of bytes to be uploaded from source file.

    • options: FileUploadRangeFromURLOptions = {}

      Options to configure File - Upload Range from URL operation.

    Returns Promise<FileUploadRangeFromURLResponse>

  • ONLY AVAILABLE IN NODE.JS RUNTIME.

    Accepts a Node.js Readable stream factory, and uploads in blocks to an Azure File. The Readable stream factory must returns a Node.js Readable stream starting from the offset defined. The offset is the offset in the Azure file to be uploaded.

    Parameters

    • streamFactory: ((offset: number, count?: number) => ReadableStream)

      Returns a Node.js Readable stream starting from the offset defined

        • (offset, count?): ReadableStream
        • Parameters

          • offset: number
          • Optionalcount: number

          Returns ReadableStream

    • size: number

      Size of the Azure file

    • options: FileParallelUploadOptions = {}

    Returns Promise<void>

  • ONLY AVAILABLE IN BROWSERS.

    Uploads a browser Blob object to an Azure file. Requires a blobFactory as the data source, which need to return a Blob object with the offset and size provided.

    Parameters

    • blobFactory: ((offset: number, size: number) => Blob)
        • (offset, size): Blob
        • Parameters

          • offset: number
          • size: number

          Returns Blob

    • size: number
    • options: FileParallelUploadOptions = {}

    Returns Promise<void>

  • ONLY AVAILABLE IN NODE.JS RUNTIME.

    Creates a new Azure File or replaces an existing Azure File, and then uploads a Node.js Readable stream into it. This method will try to create an Azure File, then starts uploading chunk by chunk. Size of chunk is defined by bufferSize parameter. Please make sure potential size of stream doesn't exceed file size.

    PERFORMANCE IMPROVEMENT TIPS:

    • Input stream highWaterMark is better to set a same value with bufferSize parameter, which will avoid Buffer.concat() operations.

    Parameters

    • stream: Readable

      Node.js Readable stream. Must be less or equal than file size.

    • size: number

      Size of file to be created. Maximum size allowed is 4 TB. If this value is larger than stream size, there will be empty bytes in file tail.

    • bufferSize: number

      Size of every buffer allocated in bytes, also the chunk/range size during the uploaded file. Size must be greater than 0 and lesser than or equal to 4 * 1024 * 1024 (4MB)

    • maxBuffers: number

      Max buffers will allocate during uploading, positive correlation with max uploading concurrency

    • options: FileUploadStreamOptions = {}

    Returns Promise<void>

  • Creates a new ShareFileClient object identical to the source but with the specified share snapshot timestamp. Provide "" will remove the snapshot and return a URL to the base ShareFileClient.

    Parameters

    • shareSnapshot: string

      The share snapshot timestamp.

    Returns ShareFileClient

    A new ShareFileClient object identical to the source but with the specified share snapshot timestamp.