Constructors

Methods

  • Check if this operator can work correctly.

    We will send a list request to the given path and return any errors we met.

    Example

    await op.check();
    

    Returns Promise<void>

  • Copy file according to given from and to path.

    Example

    await op.copy("path/to/file", "path/to/dest");
    

    Parameters

    • from: string
    • to: string

    Returns Promise<void>

  • Copy file according to given from and to path synchronously.

    Example

    op.copySync("path/to/file", "path/to/dest");
    

    Parameters

    • from: string
    • to: string

    Returns void

  • Create dir with a given path.

    Example

    await op.createDir("path/to/dir/");
    

    Parameters

    • path: string

    Returns Promise<void>

  • Create dir with a given path synchronously.

    Example

    op.createDirSync("path/to/dir/");
    

    Parameters

    • path: string

    Returns void

  • Delete the given path.

    Notes

    Delete not existing error won’t return errors.

    Example

    await op.delete("test");
    

    Parameters

    • path: string

    Returns Promise<void>

  • Delete the given path synchronously.

    Example

    op.deleteSync("test");
    

    Parameters

    • path: string

    Returns void

  • Check if this path exists or not.

    Example

    await op.isExist("test");
    

    Parameters

    • path: string

    Returns Promise<boolean>

  • Check if this path exists or not synchronously.

    Example

    op.isExistSync("test");
    

    Parameters

    • path: string

    Returns boolean

  • List the given path.

    This function will return an array of entries.

    An error will be returned if given path doesn't end with /.

    Example

    const list = await op.list("path/to/dir/");
    for (let entry of list) {
    let meta = await op.stat(entry.path);
    if (meta.isFile) {
    // do something
    }
    }

    List recursively

    With recursive option, you can list recursively.

    const list = await op.list("path/to/dir/", { recursive: true });
    for (let entry of list) {
    let meta = await op.stat(entry.path);
    if (meta.isFile) {
    // do something
    }
    }

    Parameters

    Returns Promise<Entry[]>

  • List the given path synchronously.

    This function will return an array of entries.

    An error will be returned if given path doesn't end with /.

    Example

    const list = op.listSync("path/to/dir/");
    for (let entry of list) {
    let meta = op.statSync(entry.path);
    if (meta.isFile) {
    // do something
    }
    }

    List recursively

    With recursive option, you can list recursively.

    const list = op.listSync("path/to/dir/", { recursive: true });
    for (let entry of list) {
    let meta = op.statSync(entry.path);
    if (meta.isFile) {
    // do something
    }
    }

    Parameters

    Returns Entry[]

  • Get a presigned request for read.

    Unit of expires is seconds.

    Example

    const req = await op.presignRead(path, parseInt(expires));

    console.log("method: ", req.method);
    console.log("url: ", req.url);
    console.log("headers: ", req.headers);

    Parameters

    • path: string
    • expires: number

    Returns Promise<PresignedRequest>

  • Get a presigned request for stat.

    Unit of expires is seconds.

    Example

    const req = await op.presignStat(path, parseInt(expires));

    console.log("method: ", req.method);
    console.log("url: ", req.url);
    console.log("headers: ", req.headers);

    Parameters

    • path: string
    • expires: number

    Returns Promise<PresignedRequest>

  • Get a presigned request for write.

    Unit of expires is seconds.

    Example

    const req = await op.presignWrite(path, parseInt(expires));

    console.log("method: ", req.method);
    console.log("url: ", req.url);
    console.log("headers: ", req.headers);

    Parameters

    • path: string
    • expires: number

    Returns Promise<PresignedRequest>

  • Read the whole path into a buffer.

    Example

    const buf = await op.read("path/to/file");
    

    Parameters

    • path: string

    Returns Promise<Buffer>

  • Read the whole path into a buffer synchronously.

    Example

    const buf = op.readSync("path/to/file");
    

    Parameters

    • path: string

    Returns Buffer

  • Create a reader to read the given path.

    It could be used to read large file in a streaming way.

    Parameters

    • path: string

    Returns Promise<Reader>

  • Remove given paths.

    Notes

    If underlying services support delete in batch, we will use batch delete instead.

    Examples

    await op.remove(["abc", "def"]);
    

    Parameters

    • paths: string[]

    Returns Promise<void>

  • Remove the path and all nested dirs and files recursively.

    Notes

    If underlying services support delete in batch, we will use batch delete instead.

    Examples

    await op.removeAll("path/to/dir/");
    

    Parameters

    • path: string

    Returns Promise<void>

  • Rename file according to given from and to path.

    It's similar to mv command.

    Example

    await op.rename("path/to/file", "path/to/dest");
    

    Parameters

    • from: string
    • to: string

    Returns Promise<void>

  • Rename file according to given from and to path synchronously.

    It's similar to mv command.

    Example

    op.renameSync("path/to/file", "path/to/dest");
    

    Parameters

    • from: string
    • to: string

    Returns void

  • Get current path's metadata without cache directly.

    Notes

    Use stat if you:

    • Want to detect the outside changes of a path.
    • Don’t want to read from cached metadata.

    You may want to use metadata if you are working with entries returned by Lister. It’s highly possible that metadata you want has already been cached.

    Example

    const meta = await op.stat("test");
    if (meta.isDir) {
    // do something
    }

    Parameters

    • path: string

    Returns Promise<Metadata>

  • Get current path's metadata without cache directly and synchronously.

    Example

    const meta = op.statSync("test");
    if (meta.isDir) {
    // do something
    }

    Parameters

    • path: string

    Returns Metadata

  • Write bytes into a path.

    Example

    await op.write("path/to/file", Buffer.from("hello world"));
    // or
    await op.write("path/to/file", "hello world");
    // or
    await op.write("path/to/file", Buffer.from("hello world"), { contentType: "text/plain" });

    Parameters

    • path: string
    • content: string | Buffer
    • Optional options: null | WriteOptions

    Returns Promise<void>

  • Write bytes into a path synchronously.

    Example

    op.writeSync("path/to/file", Buffer.from("hello world"));
    // or
    op.writeSync("path/to/file", "hello world");
    // or
    op.writeSync("path/to/file", Buffer.from("hello world"), { contentType: "text/plain" });

    Parameters

    • path: string
    • content: string | Buffer
    • Optional options: null | WriteOptions

    Returns void

  • Write multiple bytes into a path.

    It could be used to write large file in a streaming way.

    Parameters

    Returns Promise<Writer>

Copyright © 2022-2024, The Apache Software Foundation. Apache OpenDAL, OpenDAL, and Apache are either registered trademarks or trademarks of the Apache Software Foundation.