-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Storage] Async iterator for listing blobs and containers - storage-blob #3136
Merged
HarshaNalluru
merged 22 commits into
Azure:feature/storage
from
HarshaNalluru:AsyncIteratorsStorageBlob
May 31, 2019
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
9524d20
Async iterator for container - listBlobs
HarshaNalluru eecb12a
remove iter in the generator
HarshaNalluru 28e8773
Add marker in the generator
HarshaNalluru dc03069
yield -> yield *
HarshaNalluru bb41616
Add sample using `.next().value`
HarshaNalluru da1afa5
containerClient - *listContainers
HarshaNalluru 34e3772
udpdate - remove resumable from comment
HarshaNalluru eb3b1ca
Addressed comments
HarshaNalluru 72cd066
Add description for options attribute
HarshaNalluru 7d7cb2f
remove process.env
HarshaNalluru 7922584
un-specify the type Models.xxx
HarshaNalluru d1cf6d0
remove !options
HarshaNalluru c8128b5
rectify indentation
HarshaNalluru 49c1da6
Merge branch 'AsyncIteratorsStorageBlob' of https://github.com/Harsha…
HarshaNalluru c272c6a
listBlobs -> listBlobsFlat
HarshaNalluru 5b07b44
Add test for ListContainers
HarshaNalluru cdd3d2e
remove .only
HarshaNalluru 43d30c0
Add test for listBlobsFlat
HarshaNalluru bc932b3
resolve merge conflicts
HarshaNalluru 3fb743a
Merge remote-tracking branch 'upstream/feature/storage' into AsyncIte…
HarshaNalluru 842de33
Add test case for listBlobsFlat - for loop syntax
HarshaNalluru d7b7f71
Add test case for listContainers - for loop syntax
HarshaNalluru File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/* | ||
Setup: Enter your storage account name and shared key in main() | ||
*/ | ||
|
||
import { | ||
ContainerClient, | ||
BlobServiceClient, | ||
StorageClient, | ||
SharedKeyCredential, | ||
BlobClient, | ||
BlockBlobClient | ||
} from "../../src"; // Change to "@azure/storage-blob" in your package | ||
|
||
async function main() { | ||
// Enter your storage account name and shared key | ||
const account = ""; | ||
const accountKey = ""; | ||
|
||
// Use SharedKeyCredential with storage account and account key | ||
const sharedKeyCredential = new SharedKeyCredential(account, accountKey); | ||
|
||
// Use sharedKeyCredential, tokenCredential or anonymousCredential to create a pipeline | ||
const pipeline = StorageClient.newPipeline(sharedKeyCredential); | ||
|
||
// List containers | ||
const blobServiceClient = new BlobServiceClient( | ||
// When using AnonymousCredential, following url should include a valid SAS or support public access | ||
`https://${account}.blob.core.windows.net`, | ||
pipeline | ||
); | ||
|
||
// List Containers | ||
let iter1 = await blobServiceClient.listContainers(); | ||
let i = 1; | ||
for await (const container of iter1) { | ||
console.log(`Container ${i++}: ${container.name}`); | ||
} | ||
|
||
// List containers - generator syntax | ||
let iter2 = await blobServiceClient.listContainers(); | ||
i = 1; | ||
let containerItem = await iter2.next(); | ||
do { | ||
console.log(`Container ${i++}: ${containerItem.value.name}`); | ||
containerItem = await iter2.next(); | ||
} while (containerItem.value); | ||
|
||
// Create a container | ||
const containerName = `newcontainer${new Date().getTime()}`; | ||
const containerClient = ContainerClient.fromBlobServiceClient(blobServiceClient, containerName); | ||
|
||
const createContainerResponse = await containerClient.create(); | ||
console.log(`Created container ${containerName} successfully`, createContainerResponse.requestId); | ||
|
||
for (let index = 0; index < 4; index++) { | ||
// Create a blob | ||
let content = "hello"; | ||
let blobName = "newblob" + new Date().getTime(); | ||
let blobClient = BlobClient.fromContainerClient(containerClient, blobName); | ||
let blockBlobClient = BlockBlobClient.fromBlobClient(blobClient); | ||
let uploadBlobResponse = await blockBlobClient.upload(content, content.length); | ||
console.log(`Uploaded block blob ${blobName} successfully`, uploadBlobResponse.requestId); | ||
} | ||
|
||
// List blobs | ||
iter1 = await containerClient.listBlobsFlat(); | ||
i = 1; | ||
for await (const blob of iter1) { | ||
console.log(`Blob ${i++}: ${blob.name}`); | ||
} | ||
|
||
// List blobs - generator syntax | ||
iter2 = await containerClient.listBlobsFlat(); | ||
i = 1; | ||
let blobItem = await iter2.next(); | ||
do { | ||
console.log(`Blob ${i++}: ${blobItem.value.name}`); | ||
blobItem = await iter2.next(); | ||
} while (blobItem.value); | ||
} | ||
|
||
// An async method returns a Promise object, which is compatible with then().catch() coding style. | ||
main() | ||
.then(() => { | ||
console.log("Successfully executed the sample."); | ||
}) | ||
.catch((err) => { | ||
console.log(err.message); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just wondering what will happen if Aborter aborted iteration
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Example -
[ About 6500 containers are present in the account ]
The request was aborted
.[ X = 10000 yielded the same result ]
The request was aborted
is printed in the terminal.