Options
All
  • Public
  • Public/Protected
  • All
Menu

Index

Type aliases

TempDirOptions

TempDirOptions: { default?: undefined | false | true } & TempFileOptions

Options used by tempDir to create a temporary directory

TempDirValidationCallback

TempDirValidationCallback: (err: Error | null, name?: undefined | string) => void

Callback method can be used by tempDir when you don't want to return a Promise.

param

Error returned by tempDir call

param

directory path returned by tempDir call

Type declaration

    • (err: Error | null, name?: undefined | string): void
    • Parameters

      • err: Error | null
      • Optional name: undefined | string

      Returns void

TempDirWithFilesOptions

TempDirWithFilesOptions: { maxDepth?: undefined | number; maxFileSize?: undefined | string; maxFilesPerDir?: undefined | number; maxSubFolders?: undefined | number; randomize?: undefined | false | true } & TempDirOptions

Options used by tempDir to create a temporary directory with files

TempDirWithFilesValidationCallback

TempDirWithFilesValidationCallback: (err: Error | null, data?: [string, string[], string[]]) => void

Callback method can be used by tempDirWithFiles when you don't want to return a Promise.

param

Error returned by tempDir call

param

returning a touple of temporary folder name, list of all subfolders includind the main folder, a list of all created files

Type declaration

    • (err: Error | null, data?: [string, string[], string[]]): void
    • Parameters

      • err: Error | null
      • Optional data: [string, string[], string[]]

      Returns void

TempFileOfSizeOptions

TempFileOfSizeOptions: { size: string } & TempFileOptions

Options used by tempFileOfSize call, see description of the method.

TempFileValidationCallback

TempFileValidationCallback: (err: Error | null, file?: FileHandle) => void

Callback method can be used by tempFile when you don't want to return a Promise.

param

Error returned by tempFile call

param

FileHandle returned by tempFile call

Type declaration

    • Parameters

      Returns void

Functions

Const tempDir

  • This is a rewrite of the GoLang os.TempDir method, with additional functionality.

    tempDir creates a new temporary directory in the directory dir. The directory name is generated by taking pattern and applying a random string to the end. If pattern includes a "*", the random string replaces the last "*". tempDir returns the name of the new directory. If dir is the empty string, tempDir uses the default directory for temporary files (see os.tmpdir()). Multiple programs calling tempDir simultaneously will not choose the same directory. It is the caller's responsibility to remove the directory when no longer needed.

    If options.default is set to true in the options argument, tempDir will make use of NodeJs's fs.promises.mkdtemp method, giving as prefix the options.pattern value (which becomes mandatory).

    // will create a temporary file using the OS temporary
    // folder and a random token as filename
    const fh = tempDir()
    
    // will create a temporary file using the OS temporary
    // folder and a random token prefixed by 'tempjs_' as filename
    const fh = tempDir({ patern: 'tempjs_' })
    
    // will create a temporary file using the OS temporary
    // folder and a random token prefixed by 'tempjs_' and
    // suffixed by '.txt' as filename
    const fh = tempDir({ patern: 'tempjs_*.txt' })

    Parameters

    Returns Promise<string> | void

    Returns Promise if callback is not defined, void if callback is defined.

Const tempDirWithFiles

  • tempDirWithFiles creates a new temporary directory in the directory dir. New directory will recursively contain other a max of options.maxSubFolders (can be randomized) directories to max depth of options.maxDepth (can be randomized). Also, each folder will contain a maximum number of options.maxFilesPerDir (can be randomized), each file having the max size of options.maxFileSize (can be randomized). To randomize values, set options.randomize to true.

    For the main parent folder, function will also inherit the parameters of tempDir.

    Will return a touple of values where:

    • 1st is the path of the parent folder
    • 2nd is a list of all created folders, including parent folder
    • 3rd is a list of all created files

    Parameters

    Returns Promise<[string, string[], string[]]> | void

    Returns Promise if callback is not defined, void if callback is defined.

Const tempFile

  • This is a rewrite of the GoLang os.TempFile method, with additional functionality.

    tempFile creates a new temporary file in the directory dir, opens the file for reading and writing, and returns the resulting FileHandle. The filename is generated by taking pattern and adding a random string to the end. If pattern includes a "*", the random string replaces the last "*". If dir is the empty string, tempFile uses the default directory for temporary files (see os.tmpdir()). Multiple programs calling tempFile simultaneously will not choose the same file. The caller can use f.name to find the pathname of the file. It is the caller's responsibility to remove the file when no longer needed.

    // will create a temporary file using the OS temporary
    // folder and a random token as filename
    const fh = tempFile()
    
    // will create a temporary file using the OS temporary
    // folder and a random token prefixed by 'tempjs_' as filename
    const fh = tempFile({ patern: 'tempjs_' })
    
    // will create a temporary file using the OS temporary
    // folder and a random token prefixed by 'tempjs_' and
    // suffixed by '.txt' as filename
    const fh = tempFile({ patern: 'tempjs_*.txt' })

    Parameters

    Returns Promise<FileHandle> | void

    Returns Promise if callback is not defined, void if callback is defined.

Const tempFileOfSize

  • tempFileOfSize behaves exactly like tempFile, however it will write random data in the file, of a mentioned size. It is developer's responsibility to make sure size input is correct. See: https://www.npmjs.com/package/bytes for behavior. File's write/read cursor will be at the end of file.

    // will create a temporary file of 50Mb
    const fh = tempFileOfSize({ size: '50Mb' })

    Parameters

    Returns Promise<FileHandle> | void

    Returns Promise if callback is not defined, void if callback is defined.

Object literals

Const defaultTempDirOptions

defaultTempDirOptions: object

default

default: boolean = false

dir

dir: string = os.tmpdir()

pattern

pattern: string = ""

Legend

  • Property
  • Method
  • Property
  • Private property
  • Static method

Generated using TypeDoc