Options
All
  • Public
  • Public/Protected
  • All
Menu

Class ShareFileClient

Package version

A ShareFileClient represents a URL to an Azure Storage file.

Hierarchy

Index

Constructors

constructor

Properties

accountName

accountName: string

Protected credential

credential: Credential

Credential in the pipleline to authenticate requests to the service, such as AnonymousCredential, StorageSharedKeyCredential. Initialized to an AnonymousCredential if not able to retrieve it from the pipeline.

internal

Protected pipeline

pipeline: Pipeline

Request policy pipeline.

internal

Protected storageClientContext

storageClientContext: StorageClientContext

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

url

url: string

URL string value.

Accessors

name

  • get name(): string

path

  • get path(): string

shareName

  • get shareName(): string
  • The share name corresponding to this file client

    Returns string

Methods

abortCopyFromURL

clearRange

create

  • Creates a new file or replaces a file. Note it only initializes the file with no content.

    see

    https://docs.microsoft.com/en-us/rest/api/storageservices/create-file

    Parameters

    • size: number

      Specifies the maximum size in bytes for the file, up to 4 TB.

    • Default value options: FileCreateOptions = {}

      Options to File Create operation.

    Returns Promise<FileCreateResponse>

    Response data for the File Create 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!")

delete

  • 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)

    see

    https://docs.microsoft.com/en-us/rest/api/storageservices/delete-file2

    Parameters

    Returns Promise<FileDeleteResponse>

    Response data for the File Delete operation.

deleteIfExists

  • Removes the file from the storage account if it exists. 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)

    see

    https://docs.microsoft.com/en-us/rest/api/storageservices/delete-file2

    Parameters

    Returns Promise<FileDeleteIfExistsResponse>

download

  • download(offset?: number, count?: undefined | number, options?: FileDownloadOptions): Promise<FileDownloadResponseModel>
  • 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
    see

    https://docs.microsoft.com/en-us/rest/api/storageservices/get-file

    Parameters

    • Default value offset: number = 0

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

    • Optional count: undefined | number

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

    • Default value 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(data instanceof Buffer ? data : Buffer.from(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);
      });
    }

downloadToBuffer

  • downloadToBuffer(buffer: Buffer, offset?: undefined | number, count?: undefined | number, options?: FileDownloadToBufferOptions): Promise<Buffer>
  • downloadToBuffer(offset?: undefined | number, count?: undefined | number, options?: FileDownloadToBufferOptions): 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

    • buffer: Buffer

      Buffer to be fill, must have length larger than count

    • Optional offset: undefined | number

      From which position of the Azure File to download

    • Optional count: undefined | number

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

    • Optional options: 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

    • Optional offset: undefined | number

      From which position of the Azure file to download

    • Optional count: undefined | number

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

    • Optional options: FileDownloadToBufferOptions

      -

    Returns Promise<Buffer>

downloadToFile

  • downloadToFile(filePath: string, offset?: number, count?: undefined | number, options?: FileDownloadOptions): Promise<FileDownloadResponseModel>
  • 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

      -

    • Default value offset: number = 0

      From which position of the block blob to download.

    • Optional count: undefined | number

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

    • Default value 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.

exists

  • 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>

forceCloseAllHandles

forceCloseHandle

generateSasUrl

getProperties

getRangeList

getRangeListDiff

  • getRangeListDiff(prevShareSnapshot: string, options?: FileGetRangeListOptions): Promise<FileGetRangeListDiffResponse>
  • Returns the list of ranges that differ between a previous share snapshot and this file.

    Parameters

    • prevShareSnapshot: string

      The previous snapshot parameter is an opaque DateTime value that specifies the previous share snapshot to compare with.

    • Default value options: FileGetRangeListOptions = {}

      -

    Returns Promise<FileGetRangeListDiffResponse>

getShareLeaseClient

  • Get a ShareLeaseClient that manages leases on the file.

    Parameters

    • Optional proposeLeaseId: undefined | string

      Initial proposed lease Id.

    Returns ShareLeaseClient

    A new ShareLeaseClient object for managing leases on the file.

listHandles

  • Returns an async iterable iterator to list all the handles. under the specified account.

    .byPage() returns an async iterable iterator to list the handles in pages.

    Parameters

    • Default value options: FileListHandlesOptions = {}

      Options to list handles operation.

      An asyncIterableIterator that supports paging.

    Returns PagedAsyncIterableIterator<HandleItem, FileListHandlesResponse>

resize

  • resize(length: number, options?: FileResizeOptions): Promise<FileSetHTTPHeadersResponse>

setHttpHeaders

setMetadata

setProperties

startCopyFromURL

  • 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.

    • Default value options: FileStartCopyOptions = {}

      Options to File Start Copy operation.

    Returns Promise<FileStartCopyResponse>

uploadData

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

    Parameters

    • data: Buffer | Blob | ArrayBuffer | ArrayBufferView

      Buffer(Node), Blob, ArrayBuffer or ArrayBufferView

    • Default value options: FileParallelUploadOptions = {}

      -

    Returns Promise<void>

uploadFile

  • 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>

uploadRange

  • 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.

    • Default value 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!")

uploadRangeFromURL

  • 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.

    • Default value options: FileUploadRangeFromURLOptions = {}

      Options to configure File - Upload Range from URL operation.

    Returns Promise<FileUploadRangeFromURLResponse>

uploadResetableStream

  • uploadResetableStream(streamFactory: (offset: number, count?: undefined | number) => NodeJS.ReadableStream, size: number, options?: FileParallelUploadOptions): Promise<void>
  • 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?: undefined | number) => NodeJS.ReadableStream

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

        • (offset: number, count?: undefined | number): NodeJS.ReadableStream
        • Parameters

          • offset: number
          • Optional count: undefined | number

          Returns NodeJS.ReadableStream

    • size: number

      Size of the Azure file

    • Default value options: FileParallelUploadOptions = {}

      -

    Returns Promise<void>

uploadSeekableBlob

  • uploadSeekableBlob(blobFactory: (offset: number, size: number) => Blob, size: number, options?: FileParallelUploadOptions): 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: number, size: number): Blob
        • Parameters

          • offset: number
          • size: number

          Returns Blob

    • size: number

      -

    • Default value options: FileParallelUploadOptions = {}

      -

    Returns Promise<void>

uploadStream

  • uploadStream(stream: Readable, size: number, bufferSize: number, maxBuffers: number, options?: FileUploadStreamOptions): 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

    • Default value options: FileUploadStreamOptions = {}

      -

    Returns Promise<void>

withShareSnapshot

  • 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.

Generated using TypeDoc