import type { ExtendedSourceItem } from './ExtendedSourceItem.ts'; import type { FileItem } from './FileItem.ts'; import type { Options } from './Options.ts'; import type { Source } from './Source.ts'; import type { ZipFileContent } from './ZipFileContent.ts'; import type { SupportedBufferInput } from './append/appendArrayBuffer.ts'; import type { FromIumOptions } from './ium/from_ium.ts'; import type { ToIumOptions } from './ium/to_ium.ts'; export interface AppendPathOptions { /** * If true, the basename of the path will be kept as the relative path. * @default true */ keepBasename?: boolean; } export declare class FileCollection { readonly files: FileItem[]; readonly sources: ExtendedSourceItem[]; readonly options: Options; constructor(options?: Options, toClone?: FileCollection); /** * This is unexpected to be used directly * * About options merging, in merge in this order: * 1. options passed to the collection constructor * 2. options contained in the source * 3. options passed to the method * @param source - The source to append, which should be an ExtendedSourceItem. * @param itemOptions - Options for the item, which will be merged with the collection's options. * @private * @returns - A promise that resolves to the FileCollection instance. */ appendExtendedSource(source: ExtendedSourceItem, itemOptions?: Options): Promise; /** * Save an object to the collection. * This method will convert typed arrays to normal arrays and will * replace a potentially existing file with the same name. * @param key - The key is the relative path of the file in the collection. * @param value - The value is the object to save. * It will be serialized using JSON.stringify. * @returns A promise that resolves when the file is saved. */ set(key: string, value: any): Promise; removeFile(originalRelativePath: string): void | FileItem; get(key: string): Promise; appendWebSource(webSourceURL: string, options?: { baseURL?: string; }): Promise; /** * This method will append a list of files to the collection. * @param fileList - pass a FileList (from dom input file element or similar) or an iterable of File objects. * @returns - A promise that resolves when the files are appended. */ appendFileList(fileList: Iterable): Promise; appendSource(webSource: Source, options?: { baseURL?: string; }): Promise; /** * This method can only be used from nodejs and will throw an error in the browser * @param path - The path to the file or directory to append. * @param options - Options for appending the path. * @returns A promise that resolves when the path is appended. */ appendPath(path: string, options?: AppendPathOptions): Promise; appendText(relativePath: string, text: string | Promise, options?: { dateModified?: number; }): Promise; appendArrayBuffer(relativePath: string, arrayBuffer: SupportedBufferInput, options?: { dateModified?: number; extra?: boolean; }): Promise; /** * This method will merge the files and sources of another collection into this collection. * Sources and files will be appended to this collection. * The relative paths of the files and sources will be prefixed with the subPath. * @param other - The collection to merge into this collection. * @param subPath - Optional subPath to prefix the relative paths of the files and sources. * @returns this - The method is chainable. */ appendFileCollection(other: FileCollection, subPath?: string): this; /** * This method will generate a new FileCollection. * It filters files and sources from this collection based on the subPath. * The files and sources will have the subPath removed from their relative paths. * * Think of this method like a cd command. * Only with a relative path, and no possibility to go up. * @param subPath - The subPath to filter the files and sources by. * @returns A new FileCollection with the filtered files and sources with subPath as root. * @example * ```ts * const collection = new FileCollection(); * collection.appendText('a/b/c.txt', 'hello'); * collection.appendText('a/b/d.txt', 'world'); * collection.appendText('a/e.txt', 'hello world'); * * const subCollection = collection.subroot('a'); * * expect(subCollection.files.map((f) => f.relativePath)).toStrictEqual([ * 'b/c.txt', * 'b/d.txt', * 'e.txt', * ]); * expect(subCollection.sources.map((s) => s.relativePath)).toStrictEqual([ * 'b/c.txt', * 'b/d.txt', * 'e.txt', * ]); * ``` */ subroot(subPath: string): FileCollection; toIum(options?: ToIumOptions): Promise>; /** * This method will zip the file collection and return the zip as an ArrayBuffer * @param finalPaths - toZip will fill this map with the final paths of the sources * @returns Zip as an Uint8Array */ toZip(finalPaths?: Map): Promise>; static fromIum(ium: ZipFileContent, options?: FromIumOptions): Promise; static fromZip(zipContent: ZipFileContent, options?: Options): Promise; static fromPath(path: string, collectionOptions?: Options, options?: { keepBasename?: boolean; }): Promise; static fromSource(source: Source, collectionOptions?: Options, options?: { baseURL?: string; }): Promise; static fromCollection(collection: FileCollection, options?: Options): FileCollection; /** * Fast check if the buffer is a valid ium container. * Check the mimetype if provided. * The check assume the first entry: * - is a file with name "mimetype" * - the size of the file is in the local file header * (some zip tools can set it to 0 and put the size into the data descriptor) * - the compression method is 0 (store) * @param buffer - the buffer to check * @param mimetype - the mimetype to check as the first file in zip named "mimetype" * @returns boolean */ static isIum(buffer: ArrayBufferLike, mimetype?: string): boolean; /** * Fast check if the buffer is a zip file, checks are: * + size must be >= 22 * + 4 first bytes must be a valid zip signature * @param buffer - the buffer to check * @returns boolean */ static isZip(buffer: ArrayBufferLike): boolean; alphabetical(): this; [Symbol.iterator](): ArrayIterator; /** * Filter files of the collection based on a predicate function. * @param predicate - Function which takes a FileItem, its index, and the array of FileItems, must return a boolean. * True to keep the file, false to remove it. * @returns A new FileCollection containing only the files that match the predicate (and sources attached to these files). */ filter(predicate: (this: FileItem[], file: FileItem, index: number, array: FileItem[]) => boolean): FileCollection; } //# sourceMappingURL=FileCollection.d.ts.map