Esposter
    Preparing search index...

    Class MockContainerClient

    An in-memory mock of the Azure ContainerClient. It uses a Map to simulate blob storage.

    const mockContainerClient = new MockContainerClient("", "hello world");
    const blockBlobClient = mockContainerClient.getBlockBlobClient("hello world.txt");
    await blockBlobClient.upload("hello world", 11);
    const content = await blockBlobClient.downloadToBuffer();

    Implements

    • Except<ContainerClient, "accountName">
    Index

    Constructors

    • Parameters

      • connectionString: string
      • containerName: string

      Returns MockContainerClient

    Properties

    connectionString: string
    containerName: string

    The name of the container.

    credential: AnonymousCredential = ...

    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.

    url: string

    Encoded URL string value.

    Accessors

    • get container(): Map<string>

      Returns Map<string>

    Methods

    • Marks the specified container for deletion. The container and any blobs contained within it are later deleted during garbage collection.

      Returns Promise<ContainerDeleteResponse>

    • Marks the specified blob or snapshot for deletion. The blob is later deleted during garbage collection. Note that in order to delete a blob, you must delete all of its snapshots. You can delete both at the same time with the Delete Blob operation.

      Parameters

      • blobName: string

      Returns Promise<BlobDeleteResponse>

      Block blob deletion response data.

    • Marks the specified container for deletion if it exists. The container and any blobs contained within it are later deleted during garbage collection.

      Returns Promise<ContainerDeleteIfExistsResponse>

    • Returns true if the Azure container resource represented by this client exists; false otherwise.

      NOTE: use this function with care since an existing container might be deleted by other clients or applications. Vice versa new containers with the same name might be added by other clients or applications after this function completes.

      Returns Promise<boolean>

    • Returns an async iterable iterator to find all blobs with specified tag under the specified container.

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

      Example using for await syntax:

      import { BlobServiceClient } from "@azure/storage-blob";
      import { DefaultAzureCredential } from "@azure/identity";

      const account = "<account>";
      const blobServiceClient = new BlobServiceClient(
      `https://${account}.blob.core.windows.net`,
      new DefaultAzureCredential(),
      );

      const containerName = "<container name>";
      const containerClient = blobServiceClient.getContainerClient(containerName);

      // Example using `for await` syntax
      let i = 1;
      for await (const blob of containerClient.findBlobsByTags("tagkey='tagvalue'")) {
      console.log(`Blob ${i++}: ${blob.name}`);
      }

      // Example using `iter.next()` syntax
      i = 1;
      const iter = containerClient.findBlobsByTags("tagkey='tagvalue'");
      let { value, done } = await iter.next();
      while (!done) {
      console.log(`Blob ${i++}: ${value.name}`);
      ({ value, done } = await iter.next());
      }

      // Example using `byPage()` syntax
      i = 1;
      for await (const page of containerClient
      .findBlobsByTags("tagkey='tagvalue'")
      .byPage({ maxPageSize: 20 })) {
      for (const blob of page.blobs) {
      console.log(`Blob ${i++}: ${blob.name}`);
      }
      }

      // Example using paging with a marker
      i = 1;
      let iterator = containerClient.findBlobsByTags("tagkey='tagvalue'").byPage({ maxPageSize: 2 });
      let response = (await iterator.next()).value;
      // Prints 2 blob names
      if (response.blobs) {
      for (const blob of response.blobs) {
      console.log(`Blob ${i++}: ${blob.name}`);
      }
      }
      // Gets next marker
      let marker = response.continuationToken;
      // Passing next marker as continuationToken
      iterator = containerClient
      .findBlobsByTags("tagkey='tagvalue'")
      .byPage({ continuationToken: marker, maxPageSize: 10 });
      response = (await iterator.next()).value;
      // Prints 10 blob names
      if (response.blobs) {
      for (const blob of response.blobs) {
      console.log(`Blob ${i++}: ${blob.name}`);
      }
      }

      Returns PagedAsyncIterableIterator<
          FilterBlobItem,
          ContainerFindBlobsByTagsSegmentResponse,
      >

    • Only available for ContainerClient constructed with a shared key credential.

      Generates string to sign for a Blob Container Service Shared Access Signature (SAS) URI based on the client properties and parameters passed in. The SAS is signed by the shared key credential of the client.

      Returns string

      The SAS URI consisting of the URI to the resource represented by this client, followed by the generated SAS token.

    • Only available for ContainerClient constructed with a shared key credential.

      Generates a Blob Container Service Shared Access Signature (SAS) URI based on the client properties and parameters passed in. The SAS is signed by the shared key credential of the client.

      Returns Promise<string>

      The SAS URI consisting of the URI to the resource represented by this client, followed by the generated SAS token.

    • Generates string to sign for a Blob Container Service Shared Access Signature (SAS) URI based on the client properties and parameters passed in. The SAS is signed by the input user delegation key.

      Returns string

      The SAS URI consisting of the URI to the resource represented by this client, followed by the generated SAS token.

    • Generates a Blob Container Service Shared Access Signature (SAS) URI based on the client properties and parameters passed in. The SAS is signed by the input user delegation key.

      Returns Promise<string>

      The SAS URI consisting of the URI to the resource represented by this client, followed by the generated SAS token.

    • Gets the permissions for the specified container. The permissions indicate whether container data may be accessed publicly.

      WARNING: JavaScript Date will potentially lose precision when parsing startsOn and expiresOn strings. For example, new Date("2018-12-31T03:44:23.8827891Z").toISOString() will get "2018-12-31T03:44:23.882Z".

      Returns Promise<ContainerGetAccessPolicyResponse>

    • The Get Account Information operation returns the sku name and account kind for the specified account. The Get Account Information operation is available on service versions beginning with version 2018-03-28.

      Returns Promise<ContainerGetAccountInfoResponse>

      Response data for the Service Get Account Info operation.

    • Creates an AppendBlobClient

      Returns AppendBlobClient

    • Creates a BlobBatchClient object to conduct batch operations.

      Returns BlobBatchClient

      A new BlobBatchClient object for this container.

    • Creates a BlobClient

      Parameters

      • blobName: string

        A blob name

      Returns BlobClient

      A new BlobClient object for the given blob name.

    • Get a BlobLeaseClient that manages leases on the container.

      Returns BlobLeaseClient

      A new BlobLeaseClient object for managing leases on the container.

    • Creates a BlockBlobClient

      Parameters

      • blobName: string

        A block blob name

        Example usage:

        import { BlobServiceClient } from "@azure/storage-blob";
        import { DefaultAzureCredential } from "@azure/identity";

        const account = "<account>";
        const blobServiceClient = new BlobServiceClient(
        `https://${account}.blob.core.windows.net`,
        new DefaultAzureCredential(),
        );

        const containerName = "<container name>";
        const blobName = "<blob name>";
        const containerClient = blobServiceClient.getContainerClient(containerName);
        const blockBlobClient = containerClient.getBlockBlobClient(blobName);

        const content = "Hello world!";
        const uploadBlobResponse = await blockBlobClient.upload(content, content.length);

      Returns BlockBlobClient

    • Creates a PageBlobClient

      Returns PageBlobClient

    • Returns all user-defined metadata and system properties for the specified container. The data returned does not include the container's list of blobs.

      Returns Promise<ContainerGetPropertiesResponse>

      https://learn.microsoft.com/rest/api/storageservices/get-container-properties

      WARNING: The metadata object returned in the response will have its keys in lowercase, even if they originally contained uppercase characters. This differs from the metadata keys returned by the listContainers method of BlobServiceClient using the includeMetadata option, which will retain their original casing.

    • Returns an async iterable iterator to list all the blobs by hierarchy. under the specified account.

      .byPage() returns an async iterable iterator to list the blobs by hierarchy in pages.

      import { BlobServiceClient } from "@azure/storage-blob";
      import { DefaultAzureCredential } from "@azure/identity";

      const account = "<account>";
      const blobServiceClient = new BlobServiceClient(
      `https://${account}.blob.core.windows.net`,
      new DefaultAzureCredential(),
      );

      const containerName = "<container name>";
      const containerClient = blobServiceClient.getContainerClient(containerName);

      // Example using `for await` syntax
      let i = 1;
      const blobs = containerClient.listBlobsByHierarchy("/");
      for await (const blob of blobs) {
      if (blob.kind === "prefix") {
      console.log(`\tBlobPrefix: ${blob.name}`);
      } else {
      console.log(`\tBlobItem: name - ${blob.name}`);
      }
      }

      // Example using `iter.next()` syntax
      i = 1;
      const iter = containerClient.listBlobsByHierarchy("/");
      let { value, done } = await iter.next();
      while (!done) {
      if (value.kind === "prefix") {
      console.log(`\tBlobPrefix: ${value.name}`);
      } else {
      console.log(`\tBlobItem: name - ${value.name}`);
      }
      ({ value, done } = await iter.next());
      }

      // Example using `byPage()` syntax
      i = 1;
      for await (const page of containerClient.listBlobsByHierarchy("/").byPage({ maxPageSize: 20 })) {
      const segment = page.segment;
      if (segment.blobPrefixes) {
      for (const prefix of segment.blobPrefixes) {
      console.log(`\tBlobPrefix: ${prefix.name}`);
      }
      }
      for (const blob of page.segment.blobItems) {
      console.log(`\tBlobItem: name - ${blob.name}`);
      }
      }

      // Example using paging with a marker
      i = 1;
      let iterator = containerClient.listBlobsByHierarchy("/").byPage({ maxPageSize: 2 });
      let response = (await iterator.next()).value;
      // Prints 2 blob names
      if (response.blobPrefixes) {
      for (const prefix of response.blobPrefixes) {
      console.log(`\tBlobPrefix: ${prefix.name}`);
      }
      }
      if (response.segment.blobItems) {
      for (const blob of response.segment.blobItems) {
      console.log(`\tBlobItem: name - ${blob.name}`);
      }
      }
      // Gets next marker
      let marker = response.continuationToken;
      // Passing next marker as continuationToken
      iterator = containerClient
      .listBlobsByHierarchy("/")
      .byPage({ continuationToken: marker, maxPageSize: 10 });
      response = (await iterator.next()).value;
      // Prints 10 blob names
      if (response.blobPrefixes) {
      for (const prefix of response.blobPrefixes) {
      console.log(`\tBlobPrefix: ${prefix.name}`);
      }
      }
      if (response.segment.blobItems) {
      for (const blob of response.segment.blobItems) {
      console.log(`Blob ${i++}: ${blob.name}`);
      }
      }

      Parameters

      • delimiter: string

        The character or string used to define the virtual hierarchy

      • Optionaloptions: ContainerListBlobsOptions

        Options to list blobs operation.

      Returns PagedAsyncIterableIterator<
          BlobHierarchyItem,
          ContainerListBlobHierarchySegmentResponse,
      >

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

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

      import { BlobServiceClient } from "@azure/storage-blob";
      import { DefaultAzureCredential } from "@azure/identity";

      const account = "<account>";
      const blobServiceClient = new BlobServiceClient(
      `https://${account}.blob.core.windows.net`,
      new DefaultAzureCredential(),
      );

      const containerName = "<container name>";
      const containerClient = blobServiceClient.getContainerClient(containerName);

      // Example using `for await` syntax
      let i = 1;
      const blobs = containerClient.listBlobsFlat();
      for await (const blob of blobs) {
      console.log(`Blob ${i++}: ${blob.name}`);
      }

      // Example using `iter.next()` syntax
      i = 1;
      const iter = containerClient.listBlobsFlat();
      let { value, done } = await iter.next();
      while (!done) {
      console.log(`Blob ${i++}: ${value.name}`);
      ({ value, done } = await iter.next());
      }

      // Example using `byPage()` syntax
      i = 1;
      for await (const page of containerClient.listBlobsFlat().byPage({ maxPageSize: 20 })) {
      for (const blob of page.segment.blobItems) {
      console.log(`Blob ${i++}: ${blob.name}`);
      }
      }

      // Example using paging with a marker
      i = 1;
      let iterator = containerClient.listBlobsFlat().byPage({ maxPageSize: 2 });
      let response = (await iterator.next()).value;
      // Prints 2 blob names
      if (response.segment.blobItems) {
      for (const blob of response.segment.blobItems) {
      console.log(`Blob ${i++}: ${blob.name}`);
      }
      }
      // Gets next marker
      let marker = response.continuationToken;
      // Passing next marker as continuationToken
      iterator = containerClient.listBlobsFlat().byPage({ continuationToken: marker, maxPageSize: 10 });
      response = (await iterator.next()).value;
      // Prints 10 blob names
      if (response.segment.blobItems) {
      for (const blob of response.segment.blobItems) {
      console.log(`Blob ${i++}: ${blob.name}`);
      }
      }

      Returns PagedAsyncIterableIterator<BlobItem, ContainerListBlobFlatSegmentResponse>

      An asyncIterableIterator that supports paging.

    • Sets the permissions for the specified container. The permissions indicate whether blobs in a container may be accessed publicly.

      When you set permissions for a container, the existing permissions are replaced. If no access or containerAcl provided, the existing container ACL will be removed.

      When you establish a stored access policy on a container, it may take up to 30 seconds to take effect. During this interval, a shared access signature that is associated with the stored access policy will fail with status code 403 (Forbidden), until the access policy becomes active.

      Returns Promise<ContainerSetAccessPolicyResponse>

    • Sets one or more user-defined name-value pairs for the specified container.

      If no option provided, or no metadata defined in the parameter, the container metadata will be removed.

      Returns Promise<ContainerSetMetadataResponse>

    • Creates a new block blob, or updates the content of an existing block blob.

      Updating an existing block blob overwrites any existing metadata on the blob. Partial updates are not supported; the content of the existing blob is overwritten with the new content. To perform a partial update of a block blob's, use BlockBlobClient.stageBlock and BlockBlobClient.commitBlockList.

      This is a non-parallel uploading method, please use BlockBlobClient.uploadFile, BlockBlobClient.uploadStream or BlockBlobClient.uploadBrowserData for better performance with concurrency uploading.

      Parameters

      • blobName: string

        Name of the block blob to create or update.

      • body: RequestBodyType

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

      • contentLength: number

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

      Returns Promise<{ blockBlobClient: BlockBlobClient; response: BlockBlobUploadResponse }>

      Block Blob upload response data and the corresponding BlockBlobClient instance.