Options
All
  • Public
  • Public/Protected
  • All
Menu

Class File

Hierarchy

Index

Constructors

constructor

  • new File(path: string): File
  • Parameters

    • path: string

    Returns File

Properties

path

path: string

Static ACCESS_FILE_OK

ACCESS_FILE_OK: number = fs.constants.F_OK

表明调用进程可以读取文件

Static ACCESS_READ_OK

ACCESS_READ_OK: number = fs.constants.R_OK

表明文件对调用进程可见

Static ACCESS_WRITE_OK

ACCESS_WRITE_OK: number = fs.constants.W_OK

表明调用进程可以写入文件。

Static ACCESS_X_OK

ACCESS_X_OK: number = fs.constants.X_OK

表明调用进程可以执行文件。 在 Windows 上无效(表现得像 fs.constants.F_OK)。

Methods

access

  • access(mode?: number): Promise<void>
  • 测试对文件/目录的权限 异步

    Parameters

    • Default value mode: number = FileSystem.ACCESS_FILE_OK

    Returns Promise<void>

accessSync

  • accessSync(mode?: number): void
  • 测试对文件/目录的权限 同步

    Parameters

    • Default value mode: number = FileSystem.ACCESS_FILE_OK

    Returns void

appendAsBuffer

  • appendAsBuffer(data: Buffer): Promise<void>
  • 以buffer形式追加 同步

    Parameters

    • data: Buffer

    Returns Promise<void>

appendAsBufferSync

  • appendAsBufferSync(data: Buffer): void
  • 以buffer形式追加 异步

    Parameters

    • data: Buffer

    Returns void

appendAsString

  • appendAsString(data: string, options: { encoding?: BufferEncoding; flag?: string | number; mode?: string | number }): Promise<void>
  • 以文本形式追加 异步

    Parameters

    • data: string
    • options: { encoding?: BufferEncoding; flag?: string | number; mode?: string | number }
      • Optional encoding?: BufferEncoding
      • Optional flag?: string | number
      • Optional mode?: string | number

    Returns Promise<void>

appendAsStringSync

  • appendAsStringSync(data: string, options: { encoding?: BufferEncoding; flag?: string | number; mode?: string | number }): void
  • 以文本形式追加 同步

    Parameters

    • data: string
    • options: { encoding?: BufferEncoding; flag?: string | number; mode?: string | number }
      • Optional encoding?: BufferEncoding
      • Optional flag?: string | number
      • Optional mode?: string | number

    Returns void

copy

  • copy(path: string): Promise<File>
  • 复制文件 异步

    Parameters

    • path: string

    Returns Promise<File>

copySync

  • copySync(path: string): File
  • 复制文件同步

    Parameters

    • path: string

    Returns File

readAsBuffer

  • readAsBuffer(): Promise<Buffer>
  • 以Buffer的形式读取文件 异步

    Returns Promise<Buffer>

readAsBufferSync

  • readAsBufferSync(): Buffer
  • 以Buffer的形式读取文件 同步

    Returns Buffer

readAsStream

  • readAsStream(options?: { autoClose?: undefined | false | true; emitClose?: undefined | false | true; encoding?: undefined | string; end?: undefined | number; fd?: undefined | number; flags?: undefined | string; highWaterMark?: undefined | number; mode?: undefined | number; start?: undefined | number }): ReadStream
  • 以流的形式读取

    Parameters

    • Default value options: { autoClose?: undefined | false | true; emitClose?: undefined | false | true; encoding?: undefined | string; end?: undefined | number; fd?: undefined | number; flags?: undefined | string; highWaterMark?: undefined | number; mode?: undefined | number; start?: undefined | number } = {}
      • Optional autoClose?: undefined | false | true
      • Optional emitClose?: undefined | false | true
        default

        false

      • Optional encoding?: undefined | string
      • Optional end?: undefined | number
      • Optional fd?: undefined | number
      • Optional flags?: undefined | string
      • Optional highWaterMark?: undefined | number
      • Optional mode?: undefined | number
      • Optional start?: undefined | number

    Returns ReadStream

readAsString

  • readAsString(encoding?: BufferEncoding, flag?: string | number): Promise<string>
  • 以文本形式读取文件 异步

    Parameters

    • Default value encoding: BufferEncoding = "utf8"
    • Optional flag: string | number

    Returns Promise<string>

readAsStringSync

  • readAsStringSync(encoding?: BufferEncoding, flag?: undefined | string): string
  • 以文本形式读取文件 同步

    Parameters

    • Default value encoding: BufferEncoding = "utf8"
    • Optional flag: undefined | string

    Returns string

remove

  • remove(): Promise<void>
  • 删除文件 异步

    Returns Promise<void>

removeSync

  • removeSync(): void
  • 删除文件 同步

    Returns void

rename

  • rename(newPath: string): Promise<void>
  • 修改文件/目录名称 异步

    Parameters

    • newPath: string

    Returns Promise<void>

renameSync

  • renameSync(newPath: string): void
  • 修改文件/目录名称 同步

    Parameters

    • newPath: string

    Returns void

stat

  • stat(): Promise<Stats>
  • 获取文件/目录状态信息 异步

    Returns Promise<Stats>

statSync

  • statSync(): Stats
  • 获取文件/目录状态信息 同步

    Returns Stats

watch

  • watch(options: { encoding?: BufferEncoding | null; persistent?: undefined | false | true; recursive?: undefined | false | true }, listener?: undefined | ((event: string, filename: string) => any)): FSWatcher
  • 监听文件/目录变化

    Parameters

    • options: { encoding?: BufferEncoding | null; persistent?: undefined | false | true; recursive?: undefined | false | true }
      • Optional encoding?: BufferEncoding | null
      • Optional persistent?: undefined | false | true
      • Optional recursive?: undefined | false | true
    • Optional listener: undefined | ((event: string, filename: string) => any)

    Returns FSWatcher

writeAsBuffer

  • writeAsBuffer(data: Buffer): Promise<void>
  • 以buffer形式写入

    Parameters

    • data: Buffer

    Returns Promise<void>

writeAsBufferSync

  • writeAsBufferSync(data: Buffer): void
  • Parameters

    • data: Buffer

    Returns void

writeAsStream

  • writeAsStream(options?: { autoClose?: undefined | false | true; emitClose?: undefined | false | true; encoding?: undefined | string; fd?: undefined | number; flags?: undefined | string; highWaterMark?: undefined | number; mode?: undefined | number; start?: undefined | number }): WriteStream
  • 以流的形式写入

    Parameters

    • Default value options: { autoClose?: undefined | false | true; emitClose?: undefined | false | true; encoding?: undefined | string; fd?: undefined | number; flags?: undefined | string; highWaterMark?: undefined | number; mode?: undefined | number; start?: undefined | number } = {}
      • Optional autoClose?: undefined | false | true
      • Optional emitClose?: undefined | false | true
      • Optional encoding?: undefined | string
      • Optional fd?: undefined | number
      • Optional flags?: undefined | string
      • Optional highWaterMark?: undefined | number
      • Optional mode?: undefined | number
      • Optional start?: undefined | number

    Returns WriteStream

writeAsString

  • writeAsString(data: string, options: { encoding?: BufferEncoding; flag?: string | number; mode?: string | number }): Promise<void>
  • 以文本形式写入 异步

    Parameters

    • data: string
    • options: { encoding?: BufferEncoding; flag?: string | number; mode?: string | number }
      • Optional encoding?: BufferEncoding
      • Optional flag?: string | number
      • Optional mode?: string | number

    Returns Promise<void>

writeAsStringSync

  • writeAsStringSync(data: string, options: { encoding?: BufferEncoding; flag?: string | number; mode?: string | number }): void
  • 以文本形式写入 同步

    Parameters

    • data: string
    • options: { encoding?: BufferEncoding; flag?: string | number; mode?: string | number }
      • Optional encoding?: BufferEncoding
      • Optional flag?: string | number
      • Optional mode?: string | number

    Returns void

Generated using TypeDoc