{ "manifest": { "name": "@azure/storage-blob", "sdk-type": "client", "version": "12.27.0", "description": "Microsoft Azure Storage SDK for JavaScript - Blob", "main": "./dist/index.js", "module": "./dist-esm/storage-blob/src/index.js", "browser": { "./dist-esm/storage-blob/src/index.js": "./dist-esm/storage-blob/src/index.browser.js", "./dist-esm/storage-blob/src/credentials/StorageSharedKeyCredential.js": "./dist-esm/storage-blob/src/credentials/StorageSharedKeyCredential.browser.js", "./dist-esm/storage-blob/src/credentials/UserDelegationKeyCredential.js": "./dist-esm/storage-blob/src/credentials/UserDelegationKeyCredential.browser.js", "./dist-esm/storage-blob/src/policies/StorageSharedKeyCredentialPolicyV2.js": "./dist-esm/storage-blob/src/policies/StorageSharedKeyCredentialPolicyV2.browser.js", "./dist-esm/storage-blob/src/policies/StorageCorrectContentLengthPolicy.js": "./dist-esm/storage-blob/src/policies/StorageCorrectContentLengthPolicy.browser.js", "./dist-esm/storage-blob/src/utils/utils.node.js": "./dist-esm/storage-blob/src/utils/utils.browser.js", "./dist-esm/storage-blob/test/utils/index.js": "./dist-esm/storage-blob/test/utils/index.browser.js", "./dist-esm/storage-blob/src/BatchUtils.js": "./dist-esm/storage-blob/src/BatchUtils.browser.js", "./dist-esm/storage-blob/src/BlobDownloadResponse.js": "./dist-esm/storage-blob/src/BlobDownloadResponse.browser.js", "./dist-esm/storage-blob/src/BlobQueryResponse.js": "./dist-esm/storage-blob/src/BlobQueryResponse.browser.js", "./dist-esm/storage-common/src/BufferScheduler.js": "./dist-esm/storage-common/src/BufferScheduler.browser.js", "./dist-esm/storage-common/src/index.js": "./dist-esm/storage-common/src/index.browser.js", "fs": false, "os": false, "process": false }, "react-native": { "./dist/index.js": "./dist-esm/storage-blob/src/index.js" }, "types": "./types/latest/storage-blob.d.ts", "engines": { "node": ">=18.0.0" }, "scripts": { "build": "npm run clean && tsc -p . && dev-tool run bundle && dev-tool run extract-api", "build:browser": "tsc -p . && dev-tool run bundle", "build:node": "tsc -p . && dev-tool run bundle", "build:samples": "echo Obsolete;", "build:test": "tsc -p . && dev-tool run bundle", "check-format": "dev-tool run vendored prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"", "clean": "dev-tool run vendored rimraf --glob dist dist-* types temp statistics.html coverage coverage-browser .nyc_output *.tgz *.log test*.xml TEST*.xml", "clean:samples": "dev-tool run vendored rimraf samples/v12/javascript/node_modules samples/v12/typescript/node_modules samples/v12/typescript/dist samples/v12/typescript/package-lock.json samples/v12/javascript/package-lock.json", "emulator-tests": "dev-tool run vendored cross-env STORAGE_CONNECTION_STRING=UseDevelopmentStorage=true && npm run test:node", "execute:samples": "dev-tool samples run samples-dev", "extract-api": "tsc -p . && dev-tool run extract-api", "format": "dev-tool run vendored prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"", "generate:client": "autorest --typescript ./swagger/README.md", "integration-test": "npm run integration-test:node && npm run integration-test:browser", "integration-test:browser": "dev-tool run test:browser", "integration-test:node": "dev-tool run test:node-js-input -- --timeout 5000000 \"dist-esm/storage-blob/test/*.spec.js\" \"dist-esm/storage-blob/test/node/*.spec.js\"", "lint": "eslint package.json api-extractor.json README.md src test", "lint:fix": "eslint package.json api-extractor.json README.md src test --fix", "pack": "npm pack 2>&1", "test": "npm run clean && npm run build:test && npm run unit-test", "test:browser": "npm run clean && npm run build:test && npm run unit-test:browser", "test:node": "npm run clean && npm run build:test && npm run unit-test:node", "unit-test": "npm run unit-test:node && npm run unit-test:browser", "unit-test:browser": "dev-tool run test:browser", "unit-test:node": "dev-tool run test:node-ts-input -- --timeout 1200000 --exclude 'test/**/browser/*.spec.ts' 'test/**/*.spec.ts'", "update-snippets": "echo skipped" }, "files": [ "BreakingChanges.md", "dist/", "dist-esm/storage-blob/src/", "dist-esm/storage-internal-avro/src/", "dist-esm/storage-common/src/", "types/latest/storage-blob.d.ts", "README.md", "LICENSE" ], "repository": { "type": "git", "url": "https://github.com/Azure/azure-sdk-for-js.git" }, "keywords": [ "azure", "storage", "blob", "cloud", "node.js", "typescript", "javascript", "browser" ], "author": { "name": "Microsoft Corporation" }, "license": "MIT", "bugs": { "url": "https://github.com/Azure/azure-sdk-for-js/issues" }, "homepage": "https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/storage/storage-blob/", "sideEffects": false, "//metadata": { "constantPaths": [ { "path": "src/generated/src/storageClient.ts", "prefix": "packageVersion" }, { "path": "src/utils/constants.ts", "prefix": "SDK_VERSION" }, { "path": "swagger/README.md", "prefix": "package-version" } ] }, "//sampleConfiguration": { "skip": [ "advancedRequestOptions.js", "anonymousAuth.js", "azureAdAuth.js", "customPipeline.js", "customizedClientHeaders.js", "listBlobsByHierarchy.js", "listBlobs.js", "listContainers.js", "snapshots.js", "sharedKeyAuth.js" ], "productName": "Azure Storage Blob", "productSlugs": [ "azure", "azure-storage" ], "requiredResources": { "Azure Storage Account": "https://learn.microsoft.com/azure/storage/common/storage-account-overview" } }, "dependencies": { "@azure/abort-controller": "^2.1.2", "@azure/core-auth": "^1.4.0", "@azure/core-client": "^1.6.2", "@azure/core-http-compat": "^2.0.0", "@azure/core-lro": "^2.2.0", "@azure/core-paging": "^1.1.1", "@azure/core-rest-pipeline": "^1.10.1", "@azure/core-tracing": "^1.1.2", "@azure/core-util": "^1.6.1", "@azure/core-xml": "^1.4.3", "@azure/logger": "^1.0.0", "events": "^3.0.0", "tslib": "^2.2.0" }, "devDependencies": { "@azure-tools/test-credential": "^1.0.0", "@azure-tools/test-perf": "^1.0.0", "@azure-tools/test-recorder": "^3.0.0", "@azure-tools/test-utils": "^1.0.1", "@azure/dev-tool": "^1.0.0", "@azure/eslint-plugin-azure-sdk": "^3.0.0", "@azure/identity": "^4.0.1", "@types/chai": "^4.1.6", "@types/mocha": "^10.0.0", "@types/node": "^18.0.0", "chai": "^4.2.0", "dotenv": "^16.0.0", "es6-promise": "^4.2.5", "eslint": "^9.9.0", "inherits": "^2.0.3", "karma": "^6.2.0", "karma-chrome-launcher": "^3.0.0", "karma-coverage": "^2.0.0", "karma-env-preprocessor": "^0.1.1", "karma-firefox-launcher": "^2.1.3", "karma-junit-reporter": "^2.0.1", "karma-mocha": "^2.0.1", "karma-mocha-reporter": "^2.2.5", "karma-sourcemap-loader": "^0.4.0", "mocha": "^11.0.2", "nyc": "^17.0.0", "puppeteer": "^24.0.0", "source-map-support": "^0.5.9", "ts-node": "^10.0.0", "typescript": "~5.8.2", "util": "^0.12.1" }, "_registry": "npm", "_loc": "/home/josie/.cache/yarn/v6/npm-@azure-storage-blob-12.27.0-integrity/node_modules/@azure/storage-blob/package.json", "readmeFilename": "README.md", "readme": "# Azure Storage Blob client library for JavaScript\n\nAzure Storage Blob is Microsoft's object storage solution for the cloud. Blob storage is optimized for storing massive amounts of unstructured data. Unstructured data is data that does not adhere to a particular data model or definition, such as text or binary data.\n\nThis project provides a client library in JavaScript that makes it easy to consume Microsoft Azure Storage Blob service.\n\nUse the client libraries in this package to:\n\n- Get/Set Blob Service Properties\n- Create/List/Delete Containers\n- Create/Read/List/Update/Delete Block Blobs\n- Create/Read/List/Update/Delete Page Blobs\n- Create/Read/List/Update/Delete Append Blobs\n\nKey links\n\n- [Source code](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/storage/storage-blob)\n- [Package (npm)](https://www.npmjs.com/package/@azure/storage-blob/)\n- [API Reference Documentation](https://learn.microsoft.com/javascript/api/@azure/storage-blob)\n- [Product documentation](https://learn.microsoft.com/azure/storage/blobs/storage-blobs-overview)\n- [Samples](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/storage/storage-blob/samples)\n- [Azure Storage Blob REST APIs](https://learn.microsoft.com/rest/api/storageservices/blob-service-rest-api)\n\n## Getting started\n\n### Currently supported environments\n\n- [LTS versions of Node.js](https://github.com/nodejs/release#release-schedule)\n- Latest versions of Safari, Chrome, Edge, and Firefox.\n\nSee our [support policy](https://github.com/Azure/azure-sdk-for-js/blob/main/SUPPORT.md) for more details.\n\n### Prerequisites\n\n- An [Azure subscription](https://azure.microsoft.com/free/)\n- A [Storage Account](https://learn.microsoft.com/azure/storage/blobs/storage-quickstart-blobs-portal)\n\n### Install the package\n\nThe preferred way to install the Azure Storage Blob client library for JavaScript is to use the npm package manager. Type the following into a terminal window:\n\n```bash\nnpm install @azure/storage-blob\n```\n\n### Authenticate the client\n\nAzure Storage supports several ways to authenticate. In order to interact with the Azure Blob Storage service you'll need to create an instance of a Storage client - `BlobServiceClient`, `ContainerClient`, or `BlobClient` for example. See [samples for creating the `BlobServiceClient`](#create-the-blob-service-client) to learn more about authentication.\n\n- [Azure Active Directory](#with-defaultazurecredential-from-azureidentity-package)\n- [Shared Key](#with-storagesharedkeycredential)\n- [Shared access signatures](#with-sas-token)\n\n#### Azure Active Directory\n\nThe Azure Blob Storage service supports the use of Azure Active Directory to authenticate requests to its APIs. The [`@azure/identity`](https://www.npmjs.com/package/@azure/identity) package provides a variety of credential types that your application can use to do this. Please see the [README for `@azure/identity`](https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/identity/identity/README.md) for more details and samples to get you started.\n\n### Compatibility\n\nThis library is compatible with Node.js and browsers, and validated against LTS Node.js versions (>=8.16.0) and latest versions of Chrome, Firefox and Edge.\n\n#### Web Workers\n\nThis library requires certain DOM objects to be globally available when used in the browser, which web workers do not make available by default. You will need to polyfill these to make this library work in web workers.\n\nFor more information please refer to our [documentation for using Azure SDK for JS in Web Workers](https://aka.ms/azsdk/js/web-workers)\n\nThis library depends on following DOM APIs which need external polyfills loaded when used in web workers:\n\n- [`document`](https://developer.mozilla.org/docs/Web/API/Document)\n- [`DOMParser`](https://developer.mozilla.org/docs/Web/API/DOMParser)\n- [`Node`](https://developer.mozilla.org/docs/Web/API/Node)\n- [`XMLSerializer`](https://developer.mozilla.org/docs/Web/API/XMLSerializer)\n\n#### Differences between Node.js and browsers\n\nThere are differences between Node.js and browsers runtime. When getting started with this library, pay attention to APIs or classes marked with _\"ONLY AVAILABLE IN NODE.JS RUNTIME\"_ or _\"ONLY AVAILABLE IN BROWSERS\"_.\n\n- If a blob holds compressed data in `gzip` or `deflate` format and its content encoding is set accordingly, downloading behavior is different between Node.js and browsers. In Node.js storage clients will download the blob in its compressed format, while in browsers the data will be downloaded in de-compressed format.\n\n##### Features, interfaces, classes or functions only available in Node.js\n\n- Shared Key Authorization based on account name and account key\n - `StorageSharedKeyCredential`\n- Shared Access Signature(SAS) generation\n - `generateAccountSASQueryParameters()`\n - `generateBlobSASQueryParameters()`\n- Parallel uploading and downloading. Note that `BlockBlobClient.uploadData()` is available in both Node.js and browsers.\n - `BlockBlobClient.uploadFile()`\n - `BlockBlobClient.uploadStream()`\n - `BlobClient.downloadToBuffer()`\n - `BlobClient.downloadToFile()`\n\n##### Features, interfaces, classes or functions only available in browsers\n\n- Parallel uploading and downloading\n - `BlockBlobClient.uploadBrowserData()`\n\n### JavaScript Bundle\n\nTo use this client library in the browser, first you need to use a bundler. For details on how to do this, please refer to our [bundling documentation](https://aka.ms/AzureSDKBundling).\n\n### CORS\n\nYou need to set up [Cross-Origin Resource Sharing (CORS)](https://learn.microsoft.com/rest/api/storageservices/cross-origin-resource-sharing--cors--support-for-the-azure-storage-services) rules for your storage account if you need to develop for browsers. Go to Azure portal and Azure Storage Explorer, find your storage account, create new CORS rules for blob/queue/file/table service(s).\n\nFor example, you can create following CORS settings for debugging. But please customize the settings carefully according to your requirements in production environment.\n\n- Allowed origins: \\*\n- Allowed verbs: DELETE,GET,HEAD,MERGE,POST,OPTIONS,PUT\n- Allowed headers: \\*\n- Exposed headers: \\*\n- Maximum age (seconds): 86400\n\n## Key concepts\n\nBlob storage is designed for:\n\n- Serving images or documents directly to a browser.\n- Storing files for distributed access.\n- Streaming video and audio.\n- Writing to log files.\n- Storing data for backup and restore, disaster recovery, and archiving.\n- Storing data for analysis by an on-premises or Azure-hosted service.\n\nBlob storage offers three types of resources:\n\n- The _storage account_ used via `BlobServiceClient`\n- A _container_ in the storage account used via `ContainerClient`\n- A _blob_ in a container used via `BlobClient`\n\n## Examples\n\n- [Import the package](#import-the-package)\n- [Create the blob service client](#create-the-blob-service-client)\n- [Create a new container](#create-a-new-container)\n- [List the containers](#list-the-containers)\n- [Create a blob by uploading data](#create-a-blob-by-uploading-data)\n- [List blobs inside a container](#list-blobs-inside-a-container)\n- [Download a blob and convert it to a string (Node.js)](#download-a-blob-and-convert-it-to-a-string-nodejs)\n- [Download a blob and convert it to a string (Browsers)](#download-a-blob-and-convert-it-to-a-string-browsers)\n\n### Import the package\n\nTo use the clients, import the package into your file:\n\n```javascript\nconst AzureStorageBlob = require(\"@azure/storage-blob\");\n```\n\nAlternatively, selectively import only the types you need:\n\n```javascript\nconst { BlobServiceClient, StorageSharedKeyCredential } = require(\"@azure/storage-blob\");\n```\n\n### Create the blob service client\n\nThe `BlobServiceClient` requires an URL to the blob service and an access credential. It also optionally accepts some settings in the `options` parameter.\n\n#### with `DefaultAzureCredential` from `@azure/identity` package\n\n**Recommended way to instantiate a `BlobServiceClient`**\n\nSetup : Reference - Authorize access to blobs and queues with Azure Active Directory from a client application - https://learn.microsoft.com/azure/storage/common/storage-auth-aad-app\n\n- Register a new AAD application and give permissions to access Azure Storage on behalf of the signed-in user\n\n - Register a new application in the Azure Active Directory(in the azure-portal) - https://learn.microsoft.com/azure/active-directory/develop/quickstart-register-app\n - In the `API permissions` section, select `Add a permission` and choose `Microsoft APIs`.\n - Pick `Azure Storage` and select the checkbox next to `user_impersonation` and then click `Add permissions`. This would allow the application to access Azure Storage on behalf of the signed-in user.\n\n- Grant access to Azure Blob data with RBAC in the Azure Portal\n\n - RBAC roles for blobs and queues - https://learn.microsoft.com/azure/storage/common/storage-auth-aad-rbac-portal.\n - In the azure portal, go to your storage-account and assign **Storage Blob Data Contributor** role to the registered AAD application from `Access control (IAM)` tab (in the left-side-navbar of your storage account in the azure-portal).\n\n- Environment setup for the sample\n - From the overview page of your AAD Application, note down the `CLIENT ID` and `TENANT ID`. In the \"Certificates & Secrets\" tab, create a secret and note that down.\n - Make sure you have AZURE_TENANT_ID, AZURE_CLIENT_ID, AZURE_CLIENT_SECRET as environment variables to successfully execute the sample(Can leverage process.env).\n\n```javascript\nconst { DefaultAzureCredential } = require(\"@azure/identity\");\nconst { BlobServiceClient } = require(\"@azure/storage-blob\");\n\n// Enter your storage account name\nconst account = \"\";\nconst defaultAzureCredential = new DefaultAzureCredential();\n\nconst blobServiceClient = new BlobServiceClient(\n `https://${account}.blob.core.windows.net`,\n defaultAzureCredential,\n);\n```\n\nSee the [Azure AD Auth sample](https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/storage/storage-blob/samples/v12/javascript/azureAdAuth.js) for a complete example using this method.\n\n[Note - Above steps are only for Node.js]\n\n#### using connection string\n\nAlternatively, you can instantiate a `BlobServiceClient` using the `fromConnectionString()` static method with the full connection string as the argument. (The connection string can be obtained from the azure portal.) [ONLY AVAILABLE IN NODE.JS RUNTIME]\n\n```javascript\nconst { BlobServiceClient } = require(\"@azure/storage-blob\");\n\nconst connStr = \"\";\n\nconst blobServiceClient = BlobServiceClient.fromConnectionString(connStr);\n```\n\n#### with `StorageSharedKeyCredential`\n\nAlternatively, you instantiate a `BlobServiceClient` with a `StorageSharedKeyCredential` by passing account-name and account-key as arguments. (The account-name and account-key can be obtained from the azure portal.)\n[ONLY AVAILABLE IN NODE.JS RUNTIME]\n\n```javascript\nconst { BlobServiceClient, StorageSharedKeyCredential } = require(\"@azure/storage-blob\");\n\n// Enter your storage account name and shared key\nconst account = \"\";\nconst accountKey = \"\";\n\n// Use StorageSharedKeyCredential with storage account and account key\n// StorageSharedKeyCredential is only available in Node.js runtime, not in browsers\nconst sharedKeyCredential = new StorageSharedKeyCredential(account, accountKey);\nconst blobServiceClient = new BlobServiceClient(\n `https://${account}.blob.core.windows.net`,\n sharedKeyCredential,\n);\n```\n\n#### with SAS Token\n\nAlso, You can instantiate a `BlobServiceClient` with a shared access signatures (SAS). You can get the SAS token from the Azure Portal or generate one using `generateAccountSASQueryParameters()`.\n\n```javascript\nconst { BlobServiceClient } = require(\"@azure/storage-blob\");\n\nconst account = \"\";\nconst sas = \"\";\n\nconst blobServiceClient = new BlobServiceClient(`https://${account}.blob.core.windows.net?${sas}`);\n```\n\n### Create a new container\n\nUse `BlobServiceClient.getContainerClient()` to get a container client instance then create a new container resource.\n\n```javascript\nconst { DefaultAzureCredential } = require(\"@azure/identity\");\nconst { BlobServiceClient } = require(\"@azure/storage-blob\");\n\nconst account = \"\";\nconst defaultAzureCredential = new DefaultAzureCredential();\n\nconst blobServiceClient = new BlobServiceClient(\n `https://${account}.blob.core.windows.net`,\n defaultAzureCredential,\n);\n\nasync function main() {\n // Create a container\n const containerName = `newcontainer${new Date().getTime()}`;\n const containerClient = blobServiceClient.getContainerClient(containerName);\n const createContainerResponse = await containerClient.create();\n console.log(`Create container ${containerName} successfully`, createContainerResponse.requestId);\n}\n\nmain();\n```\n\n### List the containers\n\nUse `BlobServiceClient.listContainers()` function to iterate the containers,\nwith the new `for-await-of` syntax:\n\n```javascript\nconst { DefaultAzureCredential } = require(\"@azure/identity\");\nconst { BlobServiceClient } = require(\"@azure/storage-blob\");\n\nconst account = \"\";\nconst defaultAzureCredential = new DefaultAzureCredential();\n\nconst blobServiceClient = new BlobServiceClient(\n `https://${account}.blob.core.windows.net`,\n defaultAzureCredential,\n);\n\nasync function main() {\n let i = 1;\n const containers = blobServiceClient.listContainers();\n for await (const container of containers) {\n console.log(`Container ${i++}: ${container.name}`);\n }\n}\n\nmain();\n```\n\nAlternatively without using `for-await-of`:\n\n```javascript\nconst { DefaultAzureCredential } = require(\"@azure/identity\");\nconst { BlobServiceClient } = require(\"@azure/storage-blob\");\n\nconst account = \"\";\nconst defaultAzureCredential = new DefaultAzureCredential();\n\nconst blobServiceClient = new BlobServiceClient(\n `https://${account}.blob.core.windows.net`,\n defaultAzureCredential,\n);\n\nasync function main() {\n let i = 1;\n const iter = blobServiceClient.listContainers();\n let containerItem = await iter.next();\n while (!containerItem.done) {\n console.log(`Container ${i++}: ${containerItem.value.name}`);\n containerItem = await iter.next();\n }\n}\n\nmain();\n```\n\nIn addition, pagination is supported for listing too via `byPage()`:\n\n```javascript\nconst { DefaultAzureCredential } = require(\"@azure/identity\");\nconst { BlobServiceClient } = require(\"@azure/storage-blob\");\n\nconst account = \"\";\nconst defaultAzureCredential = new DefaultAzureCredential();\n\nconst blobServiceClient = new BlobServiceClient(\n `https://${account}.blob.core.windows.net`,\n defaultAzureCredential,\n);\n\nasync function main() {\n let i = 1;\n for await (const response of blobServiceClient.listContainers().byPage({ maxPageSize: 20 })) {\n if (response.containerItems) {\n for (const container of response.containerItems) {\n console.log(`Container ${i++}: ${container.name}`);\n }\n }\n }\n}\n\nmain();\n```\n\nFor a complete sample on iterating containers please see [samples/v12/typescript/src/listContainers.ts](https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/storage/storage-blob/samples/v12/typescript/src/listContainers.ts).\n\n### Create a blob by uploading data\n\n```javascript\nconst { DefaultAzureCredential } = require(\"@azure/identity\");\nconst { BlobServiceClient } = require(\"@azure/storage-blob\");\n\nconst account = \"\";\nconst defaultAzureCredential = new DefaultAzureCredential();\n\nconst blobServiceClient = new BlobServiceClient(\n `https://${account}.blob.core.windows.net`,\n defaultAzureCredential,\n);\n\nconst containerName = \"\";\n\nasync function main() {\n const containerClient = blobServiceClient.getContainerClient(containerName);\n\n const content = \"Hello world!\";\n const blobName = \"newblob\" + new Date().getTime();\n const blockBlobClient = containerClient.getBlockBlobClient(blobName);\n const uploadBlobResponse = await blockBlobClient.upload(content, content.length);\n console.log(`Upload block blob ${blobName} successfully`, uploadBlobResponse.requestId);\n}\n\nmain();\n```\n\n### List blobs inside a container\n\nSimilar to listing containers.\n\n```javascript\nconst { DefaultAzureCredential } = require(\"@azure/identity\");\nconst { BlobServiceClient } = require(\"@azure/storage-blob\");\n\nconst account = \"\";\nconst defaultAzureCredential = new DefaultAzureCredential();\n\nconst blobServiceClient = new BlobServiceClient(\n `https://${account}.blob.core.windows.net`,\n defaultAzureCredential,\n);\n\nconst containerName = \"\";\n\nasync function main() {\n const containerClient = blobServiceClient.getContainerClient(containerName);\n\n let i = 1;\n const blobs = containerClient.listBlobsFlat();\n for await (const blob of blobs) {\n console.log(`Blob ${i++}: ${blob.name}`);\n }\n}\n\nmain();\n```\n\nFor a complete sample on iterating blobs please see [samples/v12/typescript/src/listBlobsFlat.ts](https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/storage/storage-blob/samples/v12/typescript/src/listBlobsFlat.ts).\n\n### Download a blob and convert it to a string (Node.js)\n\n```javascript\nconst { DefaultAzureCredential } = require(\"@azure/identity\");\nconst { BlobServiceClient } = require(\"@azure/storage-blob\");\n\nconst account = \"\";\nconst defaultAzureCredential = new DefaultAzureCredential();\n\nconst blobServiceClient = new BlobServiceClient(\n `https://${account}.blob.core.windows.net`,\n defaultAzureCredential,\n);\n\nconst containerName = \"\";\nconst blobName = \"\";\n\nasync function main() {\n const containerClient = blobServiceClient.getContainerClient(containerName);\n const blobClient = containerClient.getBlobClient(blobName);\n\n // Get blob content from position 0 to the end\n // In Node.js, get downloaded data by accessing downloadBlockBlobResponse.readableStreamBody\n const downloadBlockBlobResponse = await blobClient.download();\n const downloaded = (\n await streamToBuffer(downloadBlockBlobResponse.readableStreamBody)\n ).toString();\n console.log(\"Downloaded blob content:\", downloaded);\n\n // [Node.js only] A helper method used to read a Node.js readable stream into a Buffer\n async function streamToBuffer(readableStream) {\n return new Promise((resolve, reject) => {\n const chunks = [];\n readableStream.on(\"data\", (data) => {\n chunks.push(typeof data === \"string\" ? Buffer.from(data) : data);\n });\n readableStream.on(\"end\", () => {\n resolve(Buffer.concat(chunks));\n });\n readableStream.on(\"error\", reject);\n });\n }\n}\n\nmain();\n```\n\n### Download a blob and convert it to a string (Browsers).\n\nPlease refer to the [JavaScript Bundle](#javascript-bundle) section for more information on using this library in the browser.\n\n```javascript\nconst { BlobServiceClient } = require(\"@azure/storage-blob\");\n\nconst account = \"\";\nconst sas = \"\";\nconst containerName = \"\";\nconst blobName = \"\";\n\nconst blobServiceClient = new BlobServiceClient(`https://${account}.blob.core.windows.net?${sas}`);\n\nasync function main() {\n const containerClient = blobServiceClient.getContainerClient(containerName);\n const blobClient = containerClient.getBlobClient(blobName);\n\n // Get blob content from position 0 to the end\n // In browsers, get downloaded data by accessing downloadBlockBlobResponse.blobBody\n const downloadBlockBlobResponse = await blobClient.download();\n const downloaded = await blobToString(await downloadBlockBlobResponse.blobBody);\n console.log(\"Downloaded blob content\", downloaded);\n\n // [Browsers only] A helper method used to convert a browser Blob into string.\n async function blobToString(blob) {\n const fileReader = new FileReader();\n return new Promise((resolve, reject) => {\n fileReader.onloadend = (ev) => {\n resolve(ev.target.result);\n };\n fileReader.onerror = reject;\n fileReader.readAsText(blob);\n });\n }\n}\n\nmain();\n```\n\nA complete example of simple scenarios is at [samples/v12/typescript/src/sharedKeyAuth.ts](https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/storage/storage-blob/samples/v12/typescript/src/sharedKeyAuth.ts).\n\n## Troubleshooting\n\nEnabling logging may help uncover useful information about failures. In order to see a log of HTTP requests and responses, set the `AZURE_LOG_LEVEL` environment variable to `info`. Alternatively, logging can be enabled at runtime by calling `setLogLevel` in the `@azure/logger`:\n\n```javascript\nconst { setLogLevel } = require(\"@azure/logger\");\n\nsetLogLevel(\"info\");\n```\n\n## Next steps\n\nMore code samples:\n\n- [Blob Storage Samples (JavaScript)](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/storage/storage-blob/samples/v12/javascript)\n- [Blob Storage Samples (TypeScript)](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/storage/storage-blob/samples/v12/typescript)\n- [Blob Storage Test Cases](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/storage/storage-blob/test/)\n\n## Contributing\n\nIf you'd like to contribute to this library, please read the [contributing guide](https://github.com/Azure/azure-sdk-for-js/blob/main/CONTRIBUTING.md) to learn more about how to build and test the code.\n\nAlso refer to [Storage specific guide](https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/storage/CONTRIBUTING.md) for additional information on setting up the test environment for storage libraries.\n", "licenseText": "Copyright (c) Microsoft Corporation.\n\nMIT License\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n" }, "artifacts": [], "remote": { "resolved": "https://registry.npmjs.org/@azure/storage-blob/-/storage-blob-12.27.0.tgz", "type": "tarball", "reference": "https://registry.npmjs.org/@azure/storage-blob/-/storage-blob-12.27.0.tgz", "hash": "", "integrity": "sha512-IQjj9RIzAKatmNca3D6bT0qJ+Pkox1WZGOg2esJF2YLHb45pQKOwGPIAV+w3rfgkj7zV3RMxpn/c6iftzSOZJQ==", "registry": "npm", "packageName": "@azure/storage-blob", "cacheIntegrity": "sha512-IQjj9RIzAKatmNca3D6bT0qJ+Pkox1WZGOg2esJF2YLHb45pQKOwGPIAV+w3rfgkj7zV3RMxpn/c6iftzSOZJQ== sha1-MGKTBBEXOihGi9OA4K0sYyjXKIo=" }, "registry": "npm", "hash": "2108e3f5123300a6ad98d71adc3e9b4f4a89f8f928c7559918e8367ac245d982c76f8e6940a3b018f20057ec37adf8248fbcd5dd1331a67fdcea27edcd239925" }