ts-netstorageapi-akamai - v1.1.1
    Preparing search index...

    Class default

    Client for the Akamai NetStorage HTTP API.

    Every operation comes in two forms: a callback method (stat, upload, ...) that receives (err, response, body), and a promise method with an Async suffix (statAsync, uploadAsync, ...) that resolves with the parsed body.

    import Netstorage from "ts-netstorageapi-akamai";

    const ns = new Netstorage({
    hostname: "example-nsu.akamaihd.net",
    keyName: "upload-user",
    key: process.env.NETSTORAGE_KEY!,
    cpCode: "123456",
    ssl: true,
    });

    const { stat } = await ns.statAsync("/123456/hello.txt");
    Index
    • Parameters

      • netstorageOpts: AkamaiConfig

        Connection settings. hostname, keyName and key are required; ssl defaults to false; proxy is an optional http(s):// proxy URL.

      Returns default

      Error if hostname, keyName or key is missing, TypeError if ssl is not a boolean.

    • Deletes a file or symlink (delete action).

      Parameters

      • ns_path: string

        Full path of the file.

      • callback: (err: any, res?: IncomingMessage, body?: DeleteResponse) => void

        Receives the error, the HTTP response and the parsed body.

      Returns void

    • Lists a directory (dir action).

      Parameters

      • opts: string | DirListOpts

        Directory path, or { path, actions } with DirOpts.

      • callback: (err: any, res?: IncomingMessage, body?: DirResponse) => void

        Receives the error, the HTTP response and the parsed body.

      Returns void

      ns.dir({ path: "/123456/images", actions: { max_entries: "100" } }, (err, res, body) => {
      if (!err && res.statusCode === 200) console.log(body.stat.file);
      });
    • Lists a directory (dir action).

      Parameters

      Returns Promise<DirResponse>

      The parsed listing: body.stat.attribs.directory and body.stat.file[].

      const { stat } = await ns.dirAsync("/123456/images");
      stat.file.forEach((f) => console.log(f.type, f.name, f.size));
    • Downloads a file to the local disk.

      Parameters

      • ns_path: string

        NetStorage file path (not a directory).

      • local_destination: string

        Local file or directory. Pass "" (or omit it in JavaScript) to use the NetStorage file name in the current directory; a directory keeps the NetStorage file name.

      • callback: (err: any, res?: IncomingMessage, body?: DownloadResponse) => void

        Receives the error, the HTTP response and { message: "Download Done." }. Check res.statusCode: the response body is written to disk whatever the status.

      Returns void

    • Downloads a file to the local disk.

      Parameters

      • ns_path: string

        NetStorage file path (not a directory).

      • local_destination: string

        Local file or directory. Pass "" to use the NetStorage file name in the current directory; a directory keeps the NetStorage file name.

      Returns Promise<DownloadResponse>

      { message: "Download Done." }. The response body is written whatever the HTTP status; use Netstorage.download if you need the status code.

    • Downloads a file into memory.

      Parameters

      • ns_path: string

        NetStorage file path (not a directory).

      • callback: (err: any, res?: IncomingMessage, body?: DownloadBufferResponse) => void

        Receives the error, the HTTP response and { buffer, message }. At runtime body.buffer holds the bytes as a binary (latin1) string; convert it with Buffer.from(body.buffer as unknown as string, "binary") for a real Buffer.

      Returns void

    • Downloads a file into memory.

      Parameters

      • ns_path: string

        NetStorage file path (not a directory).

      Returns Promise<DownloadBufferResponse>

      { buffer, message }. At runtime buffer holds the bytes as a binary (latin1) string; convert it with Buffer.from(result.buffer as unknown as string, "binary") for a real Buffer.

    • Disk usage of a directory (du action).

      Parameters

      • ns_path: string

        NetStorage directory path.

      • callback: (err: any, res?: IncomingMessage, body?: DuResponse) => void

        Receives the error, the HTTP response and the parsed body.

      Returns void

    • Disk usage of a directory (du action).

      Parameters

      • ns_path: string

        NetStorage directory path.

      Returns Promise<DuResponse>

      body.du["du-info"][0] with files and bytes (as strings).

    • Lists files recursively under a path (list action).

      Parameters

      • opts: string | DirListOpts

        Path, or { path, actions } with ListOpts.

      • callback: (err: any, res?: IncomingMessage, body?: ListResponse) => void

        Receives the error, the HTTP response and the parsed body.

      Returns void

    • Creates a directory (mkdir action).

      Parameters

      • ns_path: string

        Full path of the directory to create.

      • callback: (err: any, res?: IncomingMessage, body?: MkdirResponse) => void

        Receives the error, the HTTP response and the parsed body.

      Returns void

    • Sets the modification time of a file (mtime action).

      Parameters

      • ns_path: string

        NetStorage file path.

      • mtime: number

        Unix time in seconds (no milliseconds).

      • callback: (err: any, res?: IncomingMessage, body?: MtimeResponse) => void

        Receives the error, the HTTP response and the parsed body.

      Returns void

    • Sets the modification time of a file (mtime action).

      Parameters

      • ns_path: string

        NetStorage file path.

      • mtime: number

        Unix time in seconds (no milliseconds).

      Returns Promise<MtimeResponse>

    • Deletes a directory and everything in it (quick-delete action). Quick delete must be enabled on the CP code by Akamai.

      Parameters

      • ns_path: string

        Full path of the directory.

      • callback: (err: any, res?: IncomingMessage, body?: QuickDeleteResponse) => void

        Receives the error, the HTTP response and the parsed body.

      Returns void

    • Deletes a directory and everything in it (quick-delete action). Quick delete must be enabled on the CP code by Akamai.

      Parameters

      • ns_path: string

        Full path of the directory.

      Returns Promise<QuickDeleteResponse>

    • Renames or moves a file (rename action).

      Parameters

      • ns_target: string

        Current path.

      • ns_destination: string

        New path.

      • callback: (err: any, res?: IncomingMessage, body?: RenameResponse) => void

        Receives the error, the HTTP response and the parsed body.

      Returns void

    • Renames or moves a file (rename action).

      Parameters

      • ns_target: string

        Current path.

      • ns_destination: string

        New path.

      Returns Promise<RenameResponse>

    • Removes an empty directory (rmdir action).

      Parameters

      • ns_path: string

        Full path of the directory.

      • callback: (err: any, res?: IncomingMessage, body?: RmdirResponse) => void

        Receives the error, the HTTP response and the parsed body.

      Returns void

    • File or directory metadata (stat action).

      Parameters

      • ns_path: string

        NetStorage path.

      • callback: (err: any, res?: IncomingMessage, body?: StatResponse) => void

        Receives the error, the HTTP response and the parsed body.

      Returns void

    • File or directory metadata (stat action).

      Parameters

      • ns_path: string

        NetStorage path.

      Returns Promise<StatResponse>

      body.stat.file[0] with type, name, mtime (and size, md5 for files).

    • Creates a symbolic link (symlink action).

      Parameters

      • ns_target: string

        Existing file the link points to.

      • ns_destination: string

        Path of the new link.

      • callback: (err: any, res?: IncomingMessage, body?: SymlinkResponse) => void

        Receives the error, the HTTP response and the parsed body.

      Returns void

    • Creates a symbolic link (symlink action).

      Parameters

      • ns_target: string

        Existing file the link points to.

      • ns_destination: string

        Path of the new link.

      Returns Promise<SymlinkResponse>

    • Uploads a local file (upload action).

      Parameters

      • local_source: string

        Path of the local file.

      • ns_destination: string

        NetStorage file path, or a directory ending in / to keep the local file name.

      • callback: (err: any, res?: IncomingMessage, body?: UploadResponse) => void

        Receives the error, the HTTP response and { message: "Request Processed." } on success.

      Returns void

    • Uploads a local file (upload action).

      Parameters

      • local_source: string

        Path of the local file.

      • ns_destination: string

        NetStorage file path, or a directory ending in / to keep the local file name.

      Returns Promise<UploadResponse>

      { message: "Request Processed." } on success.

      await ns.uploadAsync("./build/app.js", "/123456/static/");
      
    • Uploads a Buffer (upload action), e.g. a generated file that never touches the disk.

      Parameters

      • local_source: Buffer

        File contents.

      • basename: string

        File name used when ns_destination ends in /.

      • ns_destination: string

        NetStorage file path, or a directory ending in /.

      • callback: (err: any, res?: IncomingMessage, body?: UploadResponse) => void

        Receives the error, the HTTP response and { message: "Request Processed." } on success.

      Returns void

    • Uploads a Buffer (upload action), e.g. a generated file that never touches the disk.

      Parameters

      • local_source: Buffer

        File contents.

      • basename: string

        File name used when ns_destination ends in /.

      • ns_destination: string

        NetStorage file path, or a directory ending in /.

      Returns Promise<UploadResponse>

      { message: "Request Processed." } on success.

      await ns.uploadBufferAsync(Buffer.from(JSON.stringify(data)), "data.json", "/123456/api/");