Options
All
  • Public
  • Public/Protected
  • All
Menu

Class PageBlobClient

Package version

PageBlobClient defines a set of operations applicable to page blobs.

Hierarchy

Index

Constructors

constructor

Properties

accountName

accountName: string

credential

credential: StorageSharedKeyCredential | AnonymousCredential | TokenCredential

Such as AnonymousCredential, StorageSharedKeyCredential or any credential from the @azure/identity package to authenticate requests to the service. You can also provide an object that implements the TokenCredential interface. If not specified, AnonymousCredential is used.

Protected isHttps

isHttps: boolean

Protected storageClientContext

storageClientContext: StorageClientContext

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

url

url: string

Encoded URL string value.

Accessors

containerName

  • get containerName(): string

name

  • get name(): string

Methods

abortCopyFromURL

beginCopyFromURL

  • Asynchronously copies a blob to a destination within the storage account. This method returns a long running operation poller that allows you to wait indefinitely until the copy is completed. You can also cancel a copy before it is completed by calling cancelOperation on the poller. Note that the onProgress callback will not be invoked if the operation completes in the first request, and attempting to cancel a completed copy will result in an error being thrown.

    In version 2012-02-12 and later, the source for a Copy Blob operation can be a committed blob in any Azure storage account. Beginning with version 2015-02-21, the source for a Copy Blob operation can be an Azure file in any Azure storage account. Only storage accounts created on or after June 7th, 2012 allow the Copy Blob operation to copy from another storage account.

    see

    https://docs.microsoft.com/en-us/rest/api/storageservices/copy-blob

    Example using automatic polling:

    const copyPoller = await blobClient.beginCopyFromURL('url');
    const result = await copyPoller.pollUntilDone();

    Example using manual polling:

    const copyPoller = await blobClient.beginCopyFromURL('url');
    while (!poller.isDone()) {
       await poller.poll();
    }
    const result = copyPoller.getResult();

    Example using progress updates:

    const copyPoller = await blobClient.beginCopyFromURL('url', {
      onProgress(state) {
        console.log(`Progress: ${state.copyProgress}`);
      }
    });
    const result = await copyPoller.pollUntilDone();

    Example using a changing polling interval (default 15 seconds):

    const copyPoller = await blobClient.beginCopyFromURL('url', {
      intervalInMs: 1000 // poll blob every 1 second for copy progress
    });
    const result = await copyPoller.pollUntilDone();

    Example using copy cancellation:

    const copyPoller = await blobClient.beginCopyFromURL('url');
    // cancel operation after starting it.
    try {
      await copyPoller.cancelOperation();
      // calls to get the result now throw PollerCancelledError
      await copyPoller.getResult();
    } catch (err) {
      if (err.name === 'PollerCancelledError') {
        console.log('The copy was cancelled.');
      }
    }

    Parameters

    • copySource: string

      url to the source Azure Blob/File.

    • Default value options: BlobBeginCopyFromURLOptions = {}

      Optional options to the Blob Start Copy From URL operation.

    Returns Promise<PollerLike<PollOperationState<BlobBeginCopyFromURLResponse>, BlobBeginCopyFromURLResponse>>

clearPages

create

createIfNotExists

createSnapshot

delete

deleteIfExists

deleteImmutabilityPolicy

download

  • Reads or downloads a blob from the system, including its metadata and properties. You can also call Get Blob to read a snapshot.

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

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

    Parameters

    • Default value offset: number = 0

      From which position of the blob 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: BlobDownloadOptions = {}

      Optional options to Blob Download operation.

      Example usage (Node.js):

      // Download and convert a blob to a string
      const downloadBlockBlobResponse = await blobClient.download();
      const downloaded = await streamToBuffer(downloadBlockBlobResponse.readableStreamBody);
      console.log("Downloaded blob content:", downloaded.toString());
      
      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 (browser):

      // Download and convert a blob to a string
      const downloadBlockBlobResponse = await blobClient.download();
      const downloaded = await blobToString(await downloadBlockBlobResponse.blobBody);
      console.log(
        "Downloaded blob content",
        downloaded
      );
      
      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);
        });
      }

    Returns Promise<BlobDownloadResponseParsed>

downloadToBuffer

  • downloadToBuffer(offset?: undefined | number, count?: undefined | number, options?: BlobDownloadToBufferOptions): Promise<Buffer>
  • downloadToBuffer(buffer: Buffer, offset?: undefined | number, count?: undefined | number, options?: BlobDownloadToBufferOptions): Promise<Buffer>
  • ONLY AVAILABLE IN NODE.JS RUNTIME.

    Downloads an Azure Blob in parallel to a buffer. Offset and count are optional, downloads the entire blob if they are not provided.

    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 blobs larger than this size, consider downloadToFile.

    Parameters

    • Optional offset: undefined | number

      From which position of the block blob to download(in bytes)

    • Optional count: undefined | number

      How much data(in bytes) to be downloaded. Will download to the end when passing undefined

    • Optional options: BlobDownloadToBufferOptions

      BlobDownloadToBufferOptions

    Returns Promise<Buffer>

  • ONLY AVAILABLE IN NODE.JS RUNTIME.

    Downloads an Azure Blob in parallel to a buffer. Offset and count are optional, downloads the entire blob if they are not provided.

    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 blobs 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 block blob to download(in bytes)

    • Optional count: undefined | number

      How much data(in bytes) to be downloaded. Will download to the end when passing undefined

    • Optional options: BlobDownloadToBufferOptions

      BlobDownloadToBufferOptions

    Returns Promise<Buffer>

downloadToFile

  • 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: BlobDownloadOptions = {}

      Options to Blob download options.

    Returns Promise<BlobDownloadResponseParsed>

    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 Azure blob resource represented by this client exists; false otherwise.

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

    Parameters

    Returns Promise<boolean>

generateSasUrl

getAppendBlobClient

getBlobLeaseClient

getBlockBlobClient

getPageBlobClient

getPageRanges

  • getPageRanges(offset?: number, count?: undefined | number, options?: PageBlobGetPageRangesOptions): Promise<PageBlobGetPageRangesResponse>

getPageRangesDiff

  • getPageRangesDiff(offset: number, count: number, prevSnapshot: string, options?: PageBlobGetPageRangesDiffOptions): Promise<PageBlobGetPageRangesDiffResponse>

getPageRangesDiffForManagedDisks

  • getPageRangesDiffForManagedDisks(offset: number, count: number, prevSnapshotUrl: string, options?: PageBlobGetPageRangesDiffOptions): Promise<PageBlobGetPageRangesDiffResponse>

getProperties

getTags

listPageRanges

  • Returns an async iterable iterator to list of page ranges for a page blob.

    see

    https://docs.microsoft.com/rest/api/storageservices/get-page-ranges

    .byPage() returns an async iterable iterator to list of page ranges for a page blob.

    Example using for await syntax:

    // Get the pageBlobClient before you run these snippets,
    // Can be obtained from `blobServiceClient.getContainerClient("<your-container-name>").getPageBlobClient("<your-blob-name>");`
    let i = 1;
    for await (const pageRange of pageBlobClient.listPageRanges()) {
      console.log(`Page range ${i++}: ${pageRange.start} - ${pageRange.end}`);
    }

    Example using iter.next():

    let i = 1;
    let iter = pageBlobClient.listPageRanges();
    let pageRangeItem = await iter.next();
    while (!pageRangeItem.done) {
      console.log(`Page range ${i++}: ${pageRangeItem.value.start} - ${pageRangeItem.value.end}, IsClear: ${pageRangeItem.value.isClear}`);
      pageRangeItem = await iter.next();
    }

    Example using byPage():

    // passing optional maxPageSize in the page settings
    let i = 1;
    for await (const response of pageBlobClient.listPageRanges().byPage({ maxPageSize: 20 })) {
      for (const pageRange of response) {
        console.log(`Page range ${i++}: ${pageRange.start} - ${pageRange.end}`);
      }
    }

    Example using paging with a marker:

    let i = 1;
    let iterator = pageBlobClient.listPageRanges().byPage({ maxPageSize: 2 });
    let response = (await iterator.next()).value;
    
    // Prints 2 page ranges
    for (const pageRange of response) {
      console.log(`Page range ${i++}: ${pageRange.start} - ${pageRange.end}`);
    }
    
    // Gets next marker
    let marker = response.continuationToken;
    
    // Passing next marker as continuationToken
    
    iterator = pageBlobClient.listPageRanges().byPage({ continuationToken: marker, maxPageSize: 10 });
    response = (await iterator.next()).value;
    
    // Prints 10 page ranges
    for (const blob of response) {
      console.log(`Page range ${i++}: ${pageRange.start} - ${pageRange.end}`);
    }

    Parameters

    • Default value offset: number = 0

      Starting byte position of the page ranges.

    • Optional count: undefined | number

      Number of bytes to get.

    • Default value options: PageBlobListPageRangesOptions = {}

      Options to the Page Blob Get Ranges operation.

    Returns PagedAsyncIterableIterator<PageRangeInfo, PageBlobGetPageRangesResponseModel>

    An asyncIterableIterator that supports paging.

listPageRangesDiff

  • Returns an async iterable iterator to list of page ranges that differ between a specified snapshot and this page blob.

    see

    https://docs.microsoft.com/rest/api/storageservices/get-page-ranges

    .byPage() returns an async iterable iterator to list of page ranges that differ between a specified snapshot and this page blob.

    Example using for await syntax:

    // Get the pageBlobClient before you run these snippets,
    // Can be obtained from `blobServiceClient.getContainerClient("<your-container-name>").getPageBlobClient("<your-blob-name>");`
    let i = 1;
    for await (const pageRange of pageBlobClient.listPageRangesDiff()) {
      console.log(`Page range ${i++}: ${pageRange.start} - ${pageRange.end}`);
    }

    Example using iter.next():

    let i = 1;
    let iter = pageBlobClient.listPageRangesDiff();
    let pageRangeItem = await iter.next();
    while (!pageRangeItem.done) {
      console.log(`Page range ${i++}: ${pageRangeItem.value.start} - ${pageRangeItem.value.end}, IsClear: ${pageRangeItem.value.isClear}`);
      pageRangeItem = await iter.next();
    }

    Example using byPage():

    // passing optional maxPageSize in the page settings
    let i = 1;
    for await (const response of pageBlobClient.listPageRangesDiff().byPage({ maxPageSize: 20 })) {
      for (const pageRange of response) {
        console.log(`Page range ${i++}: ${pageRange.start} - ${pageRange.end}`);
      }
    }

    Example using paging with a marker:

    let i = 1;
    let iterator = pageBlobClient.listPageRangesDiff().byPage({ maxPageSize: 2 });
    let response = (await iterator.next()).value;
    
    // Prints 2 page ranges
    for (const pageRange of response) {
      console.log(`Page range ${i++}: ${pageRange.start} - ${pageRange.end}`);
    }
    
    // Gets next marker
    let marker = response.continuationToken;
    
    // Passing next marker as continuationToken
    
    iterator = pageBlobClient.listPageRangesDiff().byPage({ continuationToken: marker, maxPageSize: 10 });
    response = (await iterator.next()).value;
    
    // Prints 10 page ranges
    for (const blob of response) {
      console.log(`Page range ${i++}: ${pageRange.start} - ${pageRange.end}`);
    }

    Parameters

    • offset: number

      Starting byte position of the page ranges.

    • count: number

      Number of bytes to get.

    • prevSnapshot: string

      Timestamp of snapshot to retrieve the difference.

    • Default value options: PageBlobListPageRangesDiffOptions = {}

      Options to the Page Blob Get Ranges operation.

    Returns PagedAsyncIterableIterator<PageRangeInfo, PageBlobGetPageRangesDiffResponseModel>

    An asyncIterableIterator that supports paging.

resize

setAccessTier

setHTTPHeaders

  • setHTTPHeaders(blobHTTPHeaders?: BlobHTTPHeaders, options?: BlobSetHTTPHeadersOptions): Promise<BlobSetHTTPHeadersResponse>
  • Sets system properties on the blob.

    If no value provided, or no value provided for the specified blob HTTP headers, these blob HTTP headers without a value will be cleared.

    see

    https://docs.microsoft.com/en-us/rest/api/storageservices/set-blob-properties

    Parameters

    • Optional blobHTTPHeaders: BlobHTTPHeaders

      If no value provided, or no value provided for the specified blob HTTP headers, these blob HTTP headers without a value will be cleared. A common header to set is blobContentType enabling the browser to provide functionality based on file type.

    • Default value options: BlobSetHTTPHeadersOptions = {}

      Optional options to Blob Set HTTP Headers operation.

    Returns Promise<BlobSetHTTPHeadersResponse>

setImmutabilityPolicy

setLegalHold

setMetadata

setTags

  • Sets tags on the underlying blob. A blob can have up to 10 tags. Tag keys must be between 1 and 128 characters. Tag values must be between 0 and 256 characters. Valid tag key and value characters include lower and upper case letters, digits (0-9), space (' '), plus ('+'), minus ('-'), period ('.'), foward slash ('/'), colon (':'), equals ('='), and underscore ('_').

    Parameters

    Returns Promise<BlobSetTagsResponse>

startCopyIncremental

syncCopyFromURL

undelete

updateSequenceNumber

uploadPages

uploadPagesFromURL

withSnapshot

  • Creates a new PageBlobClient object identical to the source but with the specified snapshot timestamp. Provide "" will remove the snapshot and return a Client to the base blob.

    Parameters

    • snapshot: string

      The snapshot timestamp.

    Returns PageBlobClient

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

withVersion

  • Creates a new BlobClient object pointing to a version of this blob. Provide "" will remove the versionId and return a Client to the base blob.

    Parameters

    • versionId: string

      The versionId.

    Returns BlobClient

    A new BlobClient object pointing to the version of this blob.

Generated using TypeDoc