file-entry-cache

  • Version 10.1.0
  • Published
  • 56.1 kB
  • 1 dependency
  • MIT license

Install

npm i file-entry-cache
yarn add file-entry-cache
pnpm add file-entry-cache

Overview

A lightweight cache for file metadata, ideal for processes that work on a specific set of files and only need to reprocess files that have changed since the last run

Index

Functions

function create

create: (
cacheId: string,
cacheDirectory?: string,
useCheckSum?: boolean,
currentWorkingDirectory?: string
) => FileEntryCache;

    function createFromFile

    createFromFile: (
    filePath: string,
    useCheckSum?: boolean,
    currentWorkingDirectory?: string
    ) => FileEntryCache;

      Classes

      class FileEntryCache

      class FileEntryCache {}

        constructor

        constructor(options?: FileEntryCacheOptions);
        • Create a new FileEntryCache instance

          Parameter options

          The options for the FileEntryCache

        property cache

        cache: FlatCache;
        • Get the cache

          Returns

          {FlatCache} The cache

        property currentWorkingDirectory

        currentWorkingDirectory: string;
        • Get the current working directory

          Returns

          {string | undefined} The current working directory

        property hashAlgorithm

        hashAlgorithm: string;
        • Get the hash algorithm

          Returns

          {string} The hash algorithm

        property useCheckSum

        useCheckSum: boolean;
        • Use the hash to check if the file has changed

          Returns

          {boolean} if the hash is used to check if the file has changed

        property useModifiedTime

        useModifiedTime: boolean;
        • Use the modified time to check if the file has changed

          Returns

          {boolean} if the modified time is used to check if the file has changed

        method analyzeFiles

        analyzeFiles: (files: string[]) => AnalyzedFiles;
        • Analyze the files analyzeFiles

          Parameter files

          The files to analyze

          Returns

          {AnalyzedFiles} The analysis of the files

        method createFileKey

        createFileKey: (
        filePath: string,
        options?: { currentWorkingDirectory?: string }
        ) => string;
        • Create the key for the file path used for caching. createFileKey

          Parameter filePath

          {String}

        method deleteCacheFile

        deleteCacheFile: () => boolean;
        • Delete the cache file from the disk deleteCacheFile {boolean} true if the file was deleted, false otherwise

        method destroy

        destroy: () => void;
        • Remove the cache from the file and clear the memory cache destroy

        method getAbsolutePath

        getAbsolutePath: (
        filePath: string,
        options?: { currentWorkingDirectory?: string }
        ) => string;
        • Get the Absolute Path. If it is already absolute it will return the path as is. getAbsolutePath

          Parameter filePath

          The file path to get the absolute path for

          Parameter options

          The options for getting the absolute path. The current working directory is used if not provided.

          Returns

          {string}

        method getFileDescriptor

        getFileDescriptor: (
        filePath: string,
        options?: GetFileDescriptorOptions
        ) => FileDescriptor;
        • Get the file descriptor for the file path getFileDescriptor

          Parameter filePath

          The file path to get the file descriptor for

          Parameter options

          The options for getting the file descriptor

          Returns

          The file descriptor

        method getFileDescriptorsByPath

        getFileDescriptorsByPath: (filePath: string) => FileDescriptor[];
        • Get the not found files getFileDescriptorsByPath

          Parameter filePath

          the files that you want to get from a path

          Returns

          {FileDescriptor[]} The not found files

        method getHash

        getHash: (buffer: Buffer) => string;
        • Given a buffer, calculate md5 hash of its content. getHash

          Parameter buffer

          buffer to calculate hash on {String} content hash digest

        method getUpdatedFiles

        getUpdatedFiles: (files: string[]) => string[];
        • Get the updated files getUpdatedFiles

          Parameter files

          The files to get the updated files for

          Returns

          {string[]} The updated files

        method hasFileChanged

        hasFileChanged: (filePath: string) => boolean;
        • Check if the file has changed hasFileChanged

          Parameter filePath

          The file path to check

          Returns

          {boolean} if the file has changed, false otherwise

        method isRelativePath

        isRelativePath: (filePath: string) => boolean;
        • Check if the file path is a relative path isRelativePath

          Parameter filePath

          The file path to check

          Returns

          {boolean} if the file path is a relative path, false otherwise

        method normalizeEntries

        normalizeEntries: (files?: string[]) => FileDescriptor[];
        • Get the file descriptors for the files normalizeEntries

          Parameter files

          ?: string[] - The files to get the file descriptors for

          Returns

          The file descriptors

        method reconcile

        reconcile: () => void;
        • Reconcile the cache reconcile

        method removeEntry

        removeEntry: (
        filePath: string,
        options?: { currentWorkingDirectory?: string }
        ) => void;
        • Remove and Entry From the Cache removeEntry

          Parameter filePath

          The file path to remove from the cache

        method renameAbsolutePathKeys

        renameAbsolutePathKeys: (oldPath: string, newPath: string) => void;
        • Rename the absolute path keys. This is used when a directory is changed or renamed. renameAbsolutePathKeys

          Parameter oldPath

          The old path to rename

          Parameter newPath

          The new path to rename to

        class FileEntryDefault

        class FileEntryDefault {}

          property create

          static create: (
          cacheId: string,
          cacheDirectory?: string,
          useCheckSum?: boolean,
          currentWorkingDirectory?: string
          ) => FileEntryCache;

            property createFromFile

            static createFromFile: (
            filePath: string,
            useCheckSum?: boolean,
            currentWorkingDirectory?: string
            ) => FileEntryCache;

              Type Aliases

              type AnalyzedFiles

              type AnalyzedFiles = {
              changedFiles: string[];
              notFoundFiles: string[];
              notChangedFiles: string[];
              };

                type FileDescriptor

                type FileDescriptor = {
                key: string;
                changed?: boolean;
                meta: FileDescriptorMeta;
                notFound?: boolean;
                err?: Error;
                };

                  type FileDescriptorMeta

                  type FileDescriptorMeta = {
                  size?: number;
                  mtime?: number;
                  hash?: string;
                  data?: unknown;
                  };

                    type FileEntryCacheOptions

                    type FileEntryCacheOptions = {
                    currentWorkingDirectory?: string;
                    useModifiedTime?: boolean;
                    useCheckSum?: boolean;
                    hashAlgorithm?: string;
                    cache?: FlatCacheOptions;
                    };

                      type GetFileDescriptorOptions

                      type GetFileDescriptorOptions = {
                      useCheckSum?: boolean;
                      useModifiedTime?: boolean;
                      currentWorkingDirectory?: string;
                      };

                        Package Files (1)

                        Dependencies (1)

                        Dev Dependencies (7)

                        Peer Dependencies (0)

                        No peer dependencies.

                        Badge

                        To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

                        You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/file-entry-cache.

                        • Markdown
                          [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/file-entry-cache)
                        • HTML
                          <a href="https://www.jsdocs.io/package/file-entry-cache"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>