MCPcopy Create free account
hub / github.com/denoland/std / parseXmlRecords

Function parseXmlRecords

xml/parse_records.ts:84–104  ·  view source on GitHub ↗
(
  source: AsyncIterable<string>,
  createCallbacks: (emit: (record: T) => void) => XmlEventCallbacks,
  options: ParseStreamOptions = {},
)

Source from the content-addressed store, hash-verified

82 * ```
83 */
84export async function* parseXmlRecords<T>(
85 source: AsyncIterable<string>,
86 createCallbacks: (emit: (record: T) => void) => XmlEventCallbacks,
87 options: ParseStreamOptions = {},
88): AsyncGenerator<T> {
89 const buffer: T[] = [];
90 const callbacks = createCallbacks((record) => buffer.push(record));
91 const { tokenizer, parser } = createXmlPipeline(options, callbacks);
92
93 // Fail-fast contract: a drain-then-throw approach interacts poorly with
94 // consumer break, so we propagate immediately and drop the chunk's
95 // pending records.
96 for await (const chunk of source) {
97 tokenizer.process(chunk, parser);
98 for (let i = 0; i < buffer.length; i++) yield buffer[i]!;
99 buffer.length = 0;
100 }
101 tokenizer.finalize(parser);
102 parser.finalize();
103 for (let i = 0; i < buffer.length; i++) yield buffer[i]!;
104}
105
106/**
107 * Parses an async iterable of XML byte chunks and yields records assembled

Callers 4

itemsFunction · 0.90
idsFunction · 0.90
parseXmlRecordsFromBytesFunction · 0.85

Calls 4

createXmlPipelineFunction · 0.90
processMethod · 0.80
pushMethod · 0.45
finalizeMethod · 0.45

Tested by

no test coverage detected