Options
All
  • Public
  • Public/Protected
  • All
Menu

Handy class for accessing file system resource.

Class in mainly focus on parsing image files, recognizing their formats and extensions.

Hierarchy

  • FileSystem

Index

Methods

Static createDirSync

  • createDirSync(dirPath: string): void

Static getFileExtension

  • getFileExtension(filePath: string): string
  • Try to acquire file extention from the path specified.

    Parameters

    • filePath: string

      file path

    Returns string

    file extension in form of '.xxx' or empty string if not found.

Static getFilesListWithExtensions

  • getFilesListWithExtensions(directoryPath: string, fileExtensions: string[]): string[]
  • Parse directory to find all files with extensions specified.

    retuns

    array of files paths that matches the queried extensions in directory specified.

    Parameters

    • directoryPath: string

      absolute path to directory beeing searched.

    • fileExtensions: string[]

      array of extensions to be searched for.

    Returns string[]

Static getFilesListWithFormat

  • getFilesListWithFormat(directoryPath: string, imageFormat: ImageFormat): string[]
  • Find list of files (images) in directory matching the format specified.

    note

    Method uses naive approach that is based on the file extension, it will never recognize files without known image extension.

    Parameters

    • directoryPath: string

      absolute path to the directory.

    • imageFormat: ImageFormat

      image format to be searched for.

    Returns string[]

Static getImageFormat

  • Find image file format knowing its path.

    Decodes image format based on file extentsion.

    notes

    Later on this method may be extended by reading binary image header and thus could recognize image format even without known extension.

    Parameters

    • filePath: string

      image file path to be recognized.

    Returns ImageFormat

    recognized image format or ImageFormat.UNKNOWN if not recognized.

Static getImageFormatByExtension

  • getImageFormatByExtension(fileExtension: string): ImageFormat
  • Try to recognize file extension and return mathing image format if known.

    Parameters

    • fileExtension: string

      file extension starting from "." dot character.

    Returns ImageFormat

    recognized ImageFormat enum or ImageFormat.UNKNOWN if not match was found.

Static getImageFormatExtensions

  • getImageFormatExtensions(imageFormat: ImageFormat): string[]
  • Get array of known file extensions for ImageFormat specified.

    Parameters

    • imageFormat: ImageFormat

      one of known ImageFormat specifiers.

    Returns string[]

    array of known image extensions or empty array if ImageFromat is not recognized (unknown).

Static getImageMimeType

  • getImageMimeType(filePath: string): string
  • Get file (image) MIME type string corresponding to image format.

    If file path specifies extension with unsuported mime type returns empty string.

    Parameters

    • filePath: string

      file path with one of supported image extensions.

    Returns string

    MIME type string or empty string if corresponding MIME type is not found or not supported.

Static getPathAbsolute

  • getPathAbsolute(relativePath: string): string
  • Get absolute path to the file or directory given path relative to package root.

    note

    This utility does not check resource existance but simply modifies path, which is assumed to be correct.

    Parameters

    • relativePath: string

      path relative to package root directory.

    Returns string

    absolute path to resource given.

Static listFilesSync

  • listFilesSync(pathExpression: string): string[]
  • Allows to list a content of directory or files matching expression.

    Parameters

    • pathExpression: string

      path to directory or filtering expression that supports wildcards notation (i.e.: /dirPath/*.png)

    Returns string[]

    list of files as string array.

Static readFile

  • readFile(filePath: string): Promise<Buffer>
  • Read entire content of the file asynchronously.

    Parameters

    • filePath: string

      A path to a file. If a URL is provided, it must use the file: protocol.

    Returns Promise<Buffer>

    Promise with file contents in Buffer object.

Static readFileSync

  • readFileSync(filePath: string): Buffer

Static removeDirSync

  • removeDirSync(dirPath: string, force?: boolean): void

Static removeFileSync

  • removeFileSync(filePath: string): void

Static writeFile

  • writeFile(filePath: string, data: Buffer | string): Promise<void>
  • Write entire buffer to file asynchronously, replacing the file if it already exists.

    Parameters

    • filePath: string

      file storage path.

    • data: Buffer | string

      buffer to be stored.

    Returns Promise<void>

    Promise.

Static writeFileSync

  • writeFileSync(filePath: string, data: Buffer | string): void
  • Write entire buffer to file synchronously, replacing the file if it already exists.

    Parameters

    • filePath: string

      file storage path.

    • data: Buffer | string

      buffer to be stored.

    Returns void

Generated using TypeDoc