UNPKG

@azure/storage-blob

Version:
49 lines • 2.08 kB
// Copyright (c) Microsoft Corporation. // Licensed under the MIT License. import * as coreClient from "@azure/core-client"; import { parseXML } from "@azure/core-xml"; import * as Mappers from "../generated/src/models/mappers.js"; import { readResponseBodyToBytes } from "./utils.common.js"; const listBlobsXmlSerializer = coreClient.createSerializer(Mappers, /* isXml */ true); /** * Reads a raw response body (a Node.js readable stream or a browser Blob) as text, * used for the XML fallback path. */ async function readResponseBodyToText(response) { const bytes = await readResponseBodyToBytes(response); return new TextDecoder().decode(bytes); } /** * Deserializes a List Blobs (flat) XML response body. Used when the service falls * back to XML for an account that does not support Apache Arrow; parses the * already-received stream instead of issuing a second request. * * @param response - The raw stream response from the list operation, with an XML body. */ export async function deserializeListBlobFlatSegmentXml(response) { const bodyAsText = await readResponseBodyToText(response); const parsedXml = (await parseXML(bodyAsText, { includeRoot: true, })); return { parsed: listBlobsXmlSerializer.deserialize(Mappers.ListBlobsFlatSegmentResponse, parsedXml.EnumerationResults ?? parsedXml, "EnumerationResults"), bodyAsText, }; } /** * Deserializes a List Blobs by hierarchy XML response body (see * {@link deserializeListBlobFlatSegmentXml}). * * @param response - The raw stream response from the list operation, with an XML body. */ export async function deserializeListBlobHierarchySegmentXml(response) { const bodyAsText = await readResponseBodyToText(response); const parsedXml = (await parseXML(bodyAsText, { includeRoot: true, })); return { parsed: listBlobsXmlSerializer.deserialize(Mappers.ListBlobsHierarchySegmentResponse, parsedXml.EnumerationResults ?? parsedXml, "EnumerationResults"), bodyAsText, }; } //# sourceMappingURL=blobListXmlParser.js.map