file-collection
    Preparing search index...

    Class FileCollection

    Index

    Constructors

    Properties

    files: FileItem[]
    options: Options

    Methods

    • Parameters

      • relativePath: string
      • arrayBuffer: SupportedBufferInput
      • options: { dateModified?: number; extra?: boolean } = {}

      Returns Promise<FileCollection>

    • 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.

      Parameters

      • other: FileCollection

        The collection to merge into this collection.

      • subPath: string = ''

        Optional subPath to prefix the relative paths of the files and sources.

      Returns this

      this - The method is chainable.

    • This method will append a list of files to the collection.

      Parameters

      • fileList: Iterable<File>

        pass a FileList (from dom input file element or similar) or an iterable of File objects.

      Returns Promise<FileCollection>

      • A promise that resolves when the files are appended.
    • Parameters

      • relativePath: string
      • text: string | Promise<string>
      • options: { dateModified?: number } = {}

      Returns Promise<FileCollection>

    • Filter files of the collection based on a predicate function.

      Parameters

      • predicate: (this: FileItem[], file: FileItem, index: number, array: FileItem[]) => boolean

        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 FileCollection

      A new FileCollection containing only the files that match the predicate (and sources attached to these files).

    • 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.

      Parameters

      • key: string

        The key is the relative path of the file in the collection.

      • value: any

        The value is the object to save. It will be serialized using JSON.stringify.

      Returns Promise<FileCollection>

      A promise that resolves when the file is saved.

    • 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.

      Parameters

      • subPath: string

        The subPath to filter the files and sources by.

      Returns FileCollection

      A new FileCollection with the filtered files and sources with subPath as root.

      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',
      ]);
    • This method will zip the file collection and return the zip as an ArrayBuffer

      Parameters

      • OptionalfinalPaths: Map<ExtendedSourceItem, string>

        toZip will fill this map with the final paths of the sources

      Returns Promise<Uint8Array<ArrayBuffer>>

      Zip as an Uint8Array

    • 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)

      Parameters

      • buffer: ArrayBufferLike

        the buffer to check

      • Optionalmimetype: string

        the mimetype to check as the first file in zip named "mimetype"

      Returns boolean

      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

      Parameters

      • buffer: ArrayBufferLike

        the buffer to check

      Returns boolean

      boolean