import type { ExtendedSourceItem } from '../ExtendedSourceItem.ts'; import type { FileCollection } from '../FileCollection.ts'; import { normalizeRelativePath } from '../utilities/normalize_relative_path.ts'; // eslint-disable-next-line jsdoc/require-jsdoc export async function appendFileList( fileCollection: FileCollection, fileList: Iterable, ) { await Promise.all(toSourceAppend(fileCollection, fileList)); } function* toSourceAppend( fileCollection: FileCollection, fileList: Iterable, ) { for (const file of fileList) { const source: ExtendedSourceItem = { uuid: crypto.randomUUID(), name: file.name, size: file.size, baseURL: 'ium:/', relativePath: normalizeRelativePath( // @ts-expect-error We allow file.path as alternative to webkitRelativePath file.webkitRelativePath || file.path || file.name, ), lastModified: file.lastModified, text: () => file.text(), arrayBuffer: () => file.arrayBuffer(), stream: () => file.stream(), }; yield fileCollection.appendExtendedSource(source); } }