@ionic/utils-fs

  • Version 3.1.5
  • Published
  • 26.2 kB
  • 3 dependencies
  • MIT license

Install

npm i @ionic/utils-fs
yarn add @ionic/utils-fs
pnpm add @ionic/utils-fs

Overview

Filesystem utils for Node

Index

Functions

function cacheFileChecksum

cacheFileChecksum: (p: string, checksum?: string) => Promise<void>;
  • Store a cache file containing the source file's md5 checksum hash.

    Parameter p

    The file path

    Parameter checksum

    The checksum. If excluded, the checksum is computed

function compilePaths

compilePaths: (filePath: string) => string[];
  • Given an absolute system path, compile an array of paths working backwards one directory at a time, always ending in the root directory.

    For example, '/some/dir' => ['/some/dir', '/some', '/']

    Parameter filePath

    Absolute system base path.

function fileToString

fileToString: (filePath: string) => Promise<string>;

    function findBaseDirectory

    findBaseDirectory: (dir: string, file: string) => Promise<string | undefined>;
    • Find the base directory based on the path given and a marker file to look for.

    function getFileChecksum

    getFileChecksum: (filePath: string) => Promise<string>;

      function getFileChecksums

      getFileChecksums: (p: string) => Promise<[string, string | undefined]>;
      • Return true and cached checksums for a file by its path.

        Cached checksums are stored as .md5 files next to the original file. If the cache file is missing, the cached checksum is undefined.

        Parameter p

        The file path Promise<[true checksum, cached checksum or undefined if cache file missing]>

      function getFileTree

      getFileTree: <RE = {}, DE = {}>(
      dir: string,
      {
      onError,
      onFileNode,
      onDirectoryNode,
      walkerOptions,
      }?: GetFileTreeOptions<RE, DE>
      ) => Promise<(RegularFileNode & RE) | (DirectoryNode & DE)>;
      • Compile and return a file tree structure.

        This function walks a directory structure recursively, building a nested object structure in memory that represents it. When finished, the root directory node is returned.

        Parameter dir

        The root directory from which to compile the file tree

      function isExecutableFile

      isExecutableFile: (filePath: string) => Promise<boolean>;

        function pathAccessible

        pathAccessible: (filePath: string, mode: number) => Promise<boolean>;

          function pathExecutable

          pathExecutable: (filePath: string) => Promise<boolean>;

            function pathExists

            pathExists: (filePath: string) => Promise<boolean>;

              function pathReadable

              pathReadable: (filePath: string) => Promise<boolean>;

                function pathWritable

                pathWritable: (filePath: string) => Promise<boolean>;

                  function readdirp

                  readdirp: (
                  dir: string,
                  { filter, onError, walkerOptions }?: ReaddirPOptions
                  ) => Promise<string[]>;

                    function readdirSafe

                    readdirSafe: (dir: string) => Promise<string[]>;

                      function statSafe

                      statSafe: (p: string) => Promise<fs.Stats | undefined>;

                        function tmpfilepath

                        tmpfilepath: (prefix?: string) => string;
                        • Generate a random file path within the computer's temporary directory.

                          Parameter prefix

                          Optionally provide a filename prefix.

                        function walk

                        walk: (p: string, options?: WalkerOptions) => Walker;

                          function writeStreamToFile

                          writeStreamToFile: (stream: any, destination: string) => Promise<any>;

                            Classes

                            class Walker

                            class Walker extends stream.Readable {}

                              constructor

                              constructor(p: string, options?: WalkerOptions);

                                property options

                                readonly options: WalkerOptions;

                                  property p

                                  readonly p: string;

                                    property paths

                                    readonly paths: string[];

                                      Interfaces

                                      interface DirectoryNode

                                      interface DirectoryNode {}

                                        property children

                                        children: FileNode[];

                                          property parent

                                          parent?: FileNode;

                                            property path

                                            path: string;

                                              property type

                                              type: FileType.DIRECTORY;

                                                interface GetFileTreeOptions

                                                interface GetFileTreeOptions<RE = {}, DE = {}> {}

                                                  property onDirectoryNode

                                                  readonly onDirectoryNode?: (node: DirectoryNode) => DirectoryNode & DE;
                                                  • Called whenever a directory node is added to the tree.

                                                    Directory nodes can be supplemented by returning a new object from this function.

                                                  property onError

                                                  readonly onError?: (err: Error) => void;
                                                  • Called whenever an error occurs during the walk process.

                                                    If excluded, the function will throw an error when first encountered.

                                                  property onFileNode

                                                  readonly onFileNode?: (node: RegularFileNode) => RegularFileNode & RE;
                                                  • Called whenever a file node is added to the tree.

                                                    File nodes can be supplemented by returning a new object from this function.

                                                  property walkerOptions

                                                  readonly walkerOptions?: WalkerOptions;

                                                    interface ReaddirPOptions

                                                    interface ReaddirPOptions {}

                                                      property filter

                                                      readonly filter?: (item: WalkerItem) => boolean;
                                                      • Filter out items from the walk process from the final result.

                                                        true to keep, otherwise the item is filtered out

                                                      property onError

                                                      readonly onError?: (err: Error) => void;
                                                      • Called whenever an error occurs during the walk process.

                                                        If excluded, the function will throw an error when first encountered.

                                                      property walkerOptions

                                                      readonly walkerOptions?: WalkerOptions;

                                                        interface RegularFileNode

                                                        interface RegularFileNode {}

                                                          property parent

                                                          parent: FileNode;

                                                            property path

                                                            path: string;

                                                              property type

                                                              type: FileType.FILE;

                                                                interface Walker

                                                                interface Walker extends stream.Readable {}

                                                                  method on

                                                                  on: {
                                                                  (event: 'data', callback: (item: WalkerItem) => void): this;
                                                                  (event: string, callback: (...args: any[]) => any): this;
                                                                  };

                                                                    interface WalkerItem

                                                                    interface WalkerItem {}

                                                                      property path

                                                                      path: string;

                                                                        property stats

                                                                        stats: fs.Stats;

                                                                          interface WalkerOptions

                                                                          interface WalkerOptions {}

                                                                            property pathFilter

                                                                            readonly pathFilter?: (p: string) => boolean;
                                                                            • Filter out file paths during walk.

                                                                              As the file tree is walked, this function can be used to exclude files and directories from the final result.

                                                                              It can also be used to tune performance. If a subdirectory is excluded, it is not walked.

                                                                              Parameter p

                                                                              The file path. true to include file path, otherwise it is excluded

                                                                            Enums

                                                                            enum FileType

                                                                            const enum FileType {
                                                                            FILE = 'file',
                                                                            DIRECTORY = 'directory',
                                                                            }

                                                                              member DIRECTORY

                                                                              DIRECTORY = 'directory'

                                                                                member FILE

                                                                                FILE = 'file'

                                                                                  Type Aliases

                                                                                  type FileNode

                                                                                  type FileNode = RegularFileNode | DirectoryNode;

                                                                                    Package Files (2)

                                                                                    Dependencies (3)

                                                                                    Dev Dependencies (10)

                                                                                    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/@ionic/utils-fs.

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