<commit_before>export function streamiterator(stream: PromiseLike<Body>): AsyncIterable<string | Buffer | Uint8Array>
export function streamiterator(stream: Body): AsyncIterable<string | Buffer | Uint8Array>
export function streamiterator<T>(stream: ReadableStream<T>): AsyncIterable<T>
export function streamiterator<T>(stream: ReadableStreamDefaultReader<T>): AsyncIterable<T>
export function streamiterator(stream: Blob): AsyncIterable<string | Buffer | Uint8Array>
export function streamiterator<T>(stream: AsyncIterable<T>): AsyncIterable<T>
export function streamiterator<T>(stream: Iterable<PromiseLike<T> | T>): AsyncIterable<T>

export async function* streamiterator<T = string | Buffer | Uint8Array>(
	stream:
		| PromiseLike<Body>
		| Body
		| ReadableStream<T>
		| ReadableStreamDefaultReader<T>
		| Blob
		| Iterable<PromiseLike<T> | T>
		| AsyncIterable<T>,
): AsyncIterable<T> {
	const resolved = await stream

	const reader = getStream(resolved) ?? getStream((resolved as Body)?.body)

	if (!reader) {
		throw new TypeError("argument is not a ReadableStream")
	} else if (isIterable<T>(reader)) {
		// do not use async iteration over sync iterator
		// https://github.com/tc39/ecma262/issues/1849
		for (const chunk of reader) yield chunk
	} else if (isAsyncIterable<T>(reader)) {
		yield* reader
	} else if (isReader<T>(reader)) {
		let needClose
		try {
			for (;;) {
				needClose = true
				const x = await reader.read()
				if (x.done) break
				needClose = false
				yield x.value
			}
		} finally {
			if (!needClose) await reader.cancel?.()
		}
	} else {
		throw new TypeError("argument is not a ReadableStream")<commit_msg>set return type to generator instead of iterable<commit_after>export function streamiterator(stream: PromiseLike<Body>): AsyncGenerator<string | Buffer | Uint8Array>
export function streamiterator(stream: Body): AsyncGenerator<string | Buffer | Uint8Array>
export function streamiterator<T>(stream: ReadableStream<T>): AsyncGenerator<T>
export function streamiterator<T>(stream: ReadableStreamDefaultReader<T>): AsyncGenerator<T>
export function streamiterator(stream: Blob): AsyncGenerator<string | Buffer | Uint8Array>
export function streamiterator<T>(stream: AsyncIterable<T>): AsyncGenerator<T>
export function streamiterator<T>(stream: Iterable<PromiseLike<T> | T>): AsyncGenerator<T>

export async function* streamiterator<T = string | Buffer | Uint8Array>(
	stream:
		| PromiseLike<Body>
		| Body
		| ReadableStream<T>
		| ReadableStreamDefaultReader<T>
		| Blob
		| Iterable<PromiseLike<T> | T>
		| AsyncIterable<T>,
): AsyncGenerator<T> {
	const resolved = await stream

	const reader = getStream(resolved) ?? getStream((resolved as Body)?.body)

	if (!reader) {
		throw new TypeError("argument is not a ReadableStream")
	} else if (isIterable<T>(reader)) {
		// do not use async iteration over sync iterator
		// https://github.com/tc39/ecma262/issues/1849
		for (const chunk of reader) yield chunk
	} else if (isAsyncIterable<T>(reader)) {
		for await (const chunk of reader) yield chunk
	} else if (isReader<T>(reader)) {
		let needClose
		try {
			for (;;) {
				needClose = true
				const x = await reader.read()
				if (x.done) break
				needClose = false
				yield x.value
			}
		} finally {
			if (!needClose) await reader.cancel?.()
		}
	} else {
		throw new TypeError("argument is not a ReadableStream")
{'fraction_non_alphanumeric': 0.11836250370809849, 'fraction_numerical': 0.0077128448531593, 'mean_word_length': 5.108695652173913, 'pattern_counts': {'":': 0, '<': 59, '<?xml version=': 0, '>': 59, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1963752', 'n_tokens_mistral': 1125, 'n_tokens_neox': 1031, 'n_words': 282}