NodeFileSystemWritableFileStream.d.ts 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import type { Data, FileSystemWritableFileStreamParams, IFileSystemWritableFileStream } from '../fsa/types';
  2. import type { IFileHandle } from '../node/types/misc';
  3. import type { NodeFsaFs } from './types';
  4. /**
  5. * When Chrome writes to the file, it creates a copy of the file with extension
  6. * `.crswap` and then replaces the original file with the copy only when the
  7. * `close()` method is called. If the `abort()` method is called, the `.crswap`
  8. * file is deleted.
  9. *
  10. * If a file name with with extension `.crswap` is already taken, it
  11. * creates a new swap file with extension `.1.crswap` and so on.
  12. */
  13. export declare const createSwapFile: (fs: NodeFsaFs, path: string, keepExistingData: boolean) => Promise<[handle: IFileHandle, path: string]>;
  14. interface SwapFile {
  15. /** Swap file full path name. */
  16. path: string;
  17. /** Seek offset in the file. */
  18. offset: number;
  19. /** Node.js open FileHandle. */
  20. handle?: IFileHandle;
  21. /** Resolves when swap file is ready for operations. */
  22. ready?: Promise<void>;
  23. }
  24. /**
  25. * Is a WritableStream object with additional convenience methods, which
  26. * operates on a single file on disk. The interface is accessed through the
  27. * `FileSystemFileHandle.createWritable()` method.
  28. *
  29. * @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemWritableFileStream
  30. */
  31. export declare class NodeFileSystemWritableFileStream extends WritableStream implements IFileSystemWritableFileStream {
  32. protected readonly fs: NodeFsaFs;
  33. protected readonly path: string;
  34. protected readonly swap: SwapFile;
  35. constructor(fs: NodeFsaFs, path: string, keepExistingData: boolean);
  36. /**
  37. * @sse https://developer.mozilla.org/en-US/docs/Web/API/FileSystemWritableFileStream/seek
  38. * @param position An `unsigned long` describing the byte position from the top
  39. * (beginning) of the file.
  40. */
  41. seek(position: number): Promise<void>;
  42. /**
  43. * @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemWritableFileStream/truncate
  44. * @param size An `unsigned long` of the amount of bytes to resize the stream to.
  45. */
  46. truncate(size: number): Promise<void>;
  47. protected writeBase(chunk: Data): Promise<void>;
  48. /**
  49. * @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemWritableFileStream/write
  50. */
  51. write(chunk: Data): Promise<void>;
  52. write(params: FileSystemWritableFileStreamParams): Promise<void>;
  53. }
  54. export {};