[storage] use node:stream/consumers in samples and snippets#38850
Draft
jeremymeng wants to merge 1 commit into
Draft
[storage] use node:stream/consumers in samples and snippets#38850jeremymeng wants to merge 1 commit into
jeremymeng wants to merge 1 commit into
Conversation
Replace the hand-rolled streamToBuffer/streamToString helpers in samples-dev and README/TSDoc snippets with the built-in �uffer() from `node:stream/consumers`, and mention ext() as a one-liner alternative. The generated samples/v12 mirrors are republished accordingly. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Packages impacted by this PR
@azure/storage-blob@azure/storage-file-datalake@azure/storage-file-shareIssues associated with this PR
N/A
Describe the problem that is addressed by this PR
The Node.js samples and README/TSDoc snippets under
sdk/storage/storage-*each shipped a hand-rolledstreamToBuffer/streamToStringhelper that wires updata/end/errorhandlers on the readable stream. Node.js has had a built-innode:stream/consumersmodule for this since 16.7, so the helper is unnecessary noise that obscures the actual sample logic and gives readers an outdated impression of best practice.What are the possible designs available to address the problem? If there are more than one possible design, why was the one in this PR chosen?
The samples now use
buffer()fromnode:stream/consumersto read the full payload as a NodeBuffer.buffer()was chosen overtext()because:.toString()for text.text()from the same module as the one-liner alternative when only a string is needed.Other
node:stream/consumersexports (arrayBuffer(),blob(),json()) are mentioned implicitly by linking readers to the module — we didn't want to weigh down each sample with every variation.Affected source files (the samples-dev TS samples and the test/snippets.spec.ts sources for README + TSDoc snippets):
storage-blob/samples-dev/{snapshots,errorsAndResponses}.tsand the now-unusedsamples-dev/utils/stream.tsstorage-file-datalake/samples-dev/dataLakeServiceClient.tsstorage-file-share/samples-dev/shareServiceClient.tsstorage-*/test/snippets.spec.ts(drives README sections andsrc/Clients.tsTSDoc comments)The
samples/v12/{typescript,javascript}mirrors, READMEs, and TSDoc snippets insrc/Clients.ts/src/clients.tswere regenerated viadev-tool samples publishandnpm run update-snippets, which accounts for the bulk of the touched files.Are there test cases added in this PR? (If not, why?)
No. This change only updates illustrative sample / documentation code; there is no runtime behavior change in any package. The internal
streamToBuffer*helpers undersrc/utils/utils.ts(and their existing tests) are untouched.Provide a list of related PRs (if any)
N/A
Command used to generate this PR:**(Applicable only to SDK release request PRs)
N/A
Checklists