NodeFileSystemWritableFileStream.d.ts 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. declare const WS: typeof WritableStream;
  25. /**
  26. * Is a WritableStream object with additional convenience methods, which
  27. * operates on a single file on disk. The interface is accessed through the
  28. * `FileSystemFileHandle.createWritable()` method.
  29. *
  30. * @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemWritableFileStream
  31. */
  32. export declare class NodeFileSystemWritableFileStream extends WS implements IFileSystemWritableFileStream {
  33. protected readonly fs: NodeFsaFs;
  34. protected readonly path: string;
  35. protected readonly swap: SwapFile;
  36. constructor(fs: NodeFsaFs, path: string, keepExistingData: boolean);
  37. /**
  38. * @sse https://developer.mozilla.org/en-US/docs/Web/API/FileSystemWritableFileStream/seek
  39. * @param position An `unsigned long` describing the byte position from the top
  40. * (beginning) of the file.
  41. */
  42. seek(position: number): Promise<void>;
  43. /**
  44. * @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemWritableFileStream/truncate
  45. * @param size An `unsigned long` of the amount of bytes to resize the stream to.
  46. */
  47. truncate(size: number): Promise<void>;
  48. protected writeBase(chunk: Data): Promise<void>;
  49. /**
  50. * @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystemWritableFileStream/write
  51. */
  52. write(chunk: Data): Promise<void>;
  53. write(params: FileSystemWritableFileStreamParams): Promise<void>;
  54. }
  55. export {};