@types/tmp

  • Version 0.2.6
  • Published
  • 10.4 kB
  • No dependencies
  • MIT license

Install

npm i @types/tmp
yarn add @types/tmp
pnpm add @types/tmp

Overview

TypeScript definitions for tmp

Index

Variables

variable tmpdir

const tmpdir: string;

    Functions

    function dir

    dir: { (options: DirOptions, cb: DirCallback): void; (cb: DirCallback): void };
    • Asynchronous directory creation.

      Simple temporary directory creation, it will be removed on process exit.

      If the directory still contains items on process exit, then it won't be removed.

      Example 1

      import * as tmp from 'tmp';

      tmp.dir((err, path, cleanupCallback) => { if (err) throw err;

      console.log('Dir: ', path);

      // Manual cleanup cleanupCallback(); });

    function dirSync

    dirSync: (options?: DirOptions) => DirResult;
    • Synchronous directory creation.

      Simple synchronous temporary directory creation, it will be removed on process exit.

      If the directory still contains items on process exit, then it won't be removed.

      Example 1

      import * as tmp from 'tmp';

      const tmpobj = tmp.dirSync(); console.log('Dir: ', tmpobj.name); // Manual cleanup tmpobj.removeCallback();

    function file

    file: {
    (options: FileOptionsDiscardFd, cb: FileCallbackNoFd): void;
    (options: FileOptions, cb: FileCallback): void;
    (cb: FileCallback): void;
    };
    • Asynchronous file creation.

      Simple temporary file creation, the file will be closed and unlinked on process exit.

      Example 1

      import * as tmp from 'tmp';

      tmp.file((err, path, fd, cleanupCallback) => { if (err) throw err;

      console.log('File: ', path); console.log('Filedescriptor: ', fd);

      // If we don't need the file anymore we could manually call the cleanupCallback // But that is not necessary if we didn't pass the keep option because the library // will clean after itself. cleanupCallback(); });

    function fileSync

    fileSync: {
    (options: FileOptionsDiscardFd): FileResultNoFd;
    (options?: FileOptions): FileResult;
    };
    • Synchronous file creation.

      Simple synchronous temporary file creation, the file will be closed and unlinked on process exit.

      Example 1

      import * as tmp from 'tmp';

      const tmpobj = tmp.fileSync(); console.log('File: ', tmpobj.name); console.log('Filedescriptor: ', tmpobj.fd);

      // If we don't need the file anymore we could manually call the removeCallback // But that is not necessary if we didn't pass the keep option because the library // will clean after itself. tmpobj.removeCallback();

    function setGracefulCleanup

    setGracefulCleanup: () => void;
    • Graceful cleanup.

      If graceful cleanup is set, tmp will remove all controlled temporary objects on process exit, otherwise the temporary objects will remain in place, waiting to be cleaned up on system restart or otherwise scheduled temporary object removal.

      Example 1

      import * as tmp from 'tmp';

      tmp.setGracefulCleanup();

    function tmpName

    tmpName: {
    (options: TmpNameOptions, cb: TmpNameCallback): void;
    (cb: TmpNameCallback): void;
    };
    • Asynchronous filename generation.

      Generates a unique filename in the specified directory.

      Example 1

      import * as tmp from 'tmp';

      tmp.tmpName((err, path) => { if (err) throw err;

      console.log('Created temporary filename: ', path); });

    function tmpNameSync

    tmpNameSync: (options?: TmpNameOptions) => string;
    • Synchronous filename generation.

      Synchronously generates a unique filename in the specified directory.

      Example 1

      import * as tmp from 'tmp';

      const name = tmp.tmpNameSync(); console.log('Created temporary filename: ', name);

    Interfaces

    interface DirOptions

    interface DirOptions extends TmpNameOptions {}

      property keep

      keep?: boolean | undefined;
      • Signals that the temporary file or directory should not be deleted on exit

        - In order to clean up, you will have to call the provided cleanupCallback function manually.

        false

      property mode

      mode?: number | undefined;
      • The file mode to create with. 0o700

      property unsafeCleanup

      unsafeCleanup?: boolean | undefined;
      • Recursively removes the created temporary directory, even when it's not empty. false

      interface DirResult

      interface DirResult {}

        property name

        name: string;

          property removeCallback

          removeCallback: () => void;

            interface FileOptions

            interface FileOptions extends TmpNameOptions {}

              property detachDescriptor

              detachDescriptor?: boolean | undefined;
              • Detaches the file descriptor, caller is responsible for closing the file, tmp will no longer try closing the file during garbage collection. false

              property discardDescriptor

              discardDescriptor?: boolean | undefined;
              • Discards the file descriptor (closes file, fd is -1), tmp will no longer try closing the file during garbage collection. false

              property keep

              keep?: boolean | undefined;
              • Signals that the temporary file or directory should not be deleted on exit

                - In order to clean up, you will have to call the provided cleanupCallback function manually.

                false

              property mode

              mode?: number | undefined;
              • The file mode to create with. 0o600

              interface FileOptionsDiscardFd

              interface FileOptionsDiscardFd extends FileOptions {}

                property discardDescriptor

                discardDescriptor: true;

                  interface FileResult

                  interface FileResult {}

                    property fd

                    fd: number;

                      property name

                      name: string;

                        property removeCallback

                        removeCallback: () => void;

                          interface TmpNameOptions

                          interface TmpNameOptions {}

                            property dir

                            dir?: string | undefined;
                            • The optional temporary directory that must be relative to the system's default temporary directory. Absolute paths are fine as long as they point to a location under the system's default temporary directory. Any directories along the so specified path must exist, otherwise a ENOENT error will be thrown upon access, as tmp will not check the availability of the path, nor will it establish the requested path for you.

                            property name

                            name?: string | undefined;
                            • A fixed name that overrides random name generation, the name must be relative and must not contain path segments.

                            property postfix

                            postfix?: string | undefined;
                            • The optional postfix. ''

                            property prefix

                            prefix?: string | undefined;
                            • The optional prefix. 'tmp'

                            property template

                            template?: string | undefined;
                            • [mkstemp](http://www.kernel.org/doc/man-pages/online/pages/man3/mkstemp.3.html) like filename template, no default, must include XXXXXX once for random name generation, e.g. 'foo-bar-XXXXXX'.

                            property tmpdir

                            tmpdir?: string | undefined;
                            • Allows you to override the system's root tmp directory.

                            property tries

                            tries?: number | undefined;
                            • How many times should the function try to get a unique filename before giving up. 3

                            Type Aliases

                            type DirCallback

                            type DirCallback = (
                            err: Error | null,
                            name: string,
                            removeCallback: () => void
                            ) => void;

                              type FileCallback

                              type FileCallback = (
                              err: Error | null,
                              name: string,
                              fd: number,
                              removeCallback: () => void
                              ) => void;

                                type FileCallbackNoFd

                                type FileCallbackNoFd = (
                                err: Error | null,
                                name: string,
                                fd: undefined,
                                removeCallback: () => void
                                ) => void;

                                  type FileResultNoFd

                                  type FileResultNoFd = Omit<FileResult, 'fd'>;

                                    type TmpNameCallback

                                    type TmpNameCallback = (err: Error | null, name: string) => void;

                                      Package Files (1)

                                      Dependencies (0)

                                      No dependencies.

                                      Dev Dependencies (0)

                                      No dev dependencies.

                                      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/@types/tmp.

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