Skip to content

Commit

Permalink
version: 0.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
hughfenghen committed Mar 3, 2024
1 parent 176a05d commit ffe5619
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 6 deletions.
38 changes: 36 additions & 2 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { file, write, dir } from 'opfs-tools'
## file

```ts
import { OPFSDirWrap, dir } from './directory';
/**
* Retrieves a file wrapper instance for the specified file path.
* @param {string} filePath - The path of the file.
Expand Down Expand Up @@ -37,13 +38,20 @@ export declare function file(filePath: string): OPFSFileWrap;
* // Write content to a file
await write('/path/to/file.txt', 'Hello, world!');
*/
export declare function write(filePath: string, content: string | BufferSource | ReadableStream<BufferSource>): Promise<void>;
export declare function write(filePath: string, content: string | BufferSource | ReadableStream<BufferSource> | OPFSFileWrap): Promise<void>;
/**
* Represents a wrapper for interacting with a file in the filesystem.
*/
export declare class OPFSFileWrap {
#private;
get kind(): 'file';
get path(): string;
get name(): string;
get parent(): ReturnType<typeof dir> | null;
constructor(filePath: string);
/**
* Random write to file
*/
createWriter(): Promise<{
write: (chunk: string | BufferSource, opts?: {
at?: number;
Expand All @@ -52,6 +60,9 @@ export declare class OPFSFileWrap {
flush: () => Promise<void>;
close: () => Promise<void>;
}>;
/**
* Random access to file
*/
createReader(): Promise<{
read: (size: number, opts?: {
at?: number;
Expand All @@ -65,6 +76,15 @@ export declare class OPFSFileWrap {
getSize(): Promise<number>;
exists(): Promise<boolean>;
remove(): Promise<void>;
/**
* If the target is a file, use current overwrite the target;
* if the target is a folder, copy the current file into that folder.
*/
copyTo(target: OPFSDirWrap | OPFSFileWrap): Promise<OPFSFileWrap>;
/**
* move file, copy then remove current
*/
moveTo(target: OPFSDirWrap | OPFSFileWrap): Promise<OPFSFileWrap>;
}
```

Expand All @@ -74,6 +94,7 @@ export declare class OPFSFileWrap {
import { OPFSFileWrap } from './file';
declare global {
interface FileSystemDirectoryHandle {
keys: () => AsyncIterable<string>;
values: () => AsyncIterable<FileSystemDirectoryHandle | FileSystemFileHandle>;
}
}
Expand All @@ -95,8 +116,12 @@ declare global {
const children = await dir('/path/to/parent_directory').children();
*/
export declare function dir(dirPath: string): OPFSDirWrap;
declare class OPFSDirWrap {
export declare class OPFSDirWrap {
#private;
get kind(): 'dir';
get name(): string;
get path(): string;
get parent(): OPFSDirWrap | null;
constructor(dirPath: string);
/**
* Creates the directory.
Expand All @@ -118,5 +143,14 @@ declare class OPFSDirWrap {
* return A promise that resolves to an array of objects representing the children.
*/
children(): Promise<Array<OPFSDirWrap | OPFSFileWrap>>;
/**
* If the dest folder exists, copy the current directory into the dest folder;
* if the dest folder does not exist, rename the current directory to dest name.
*/
copyTo(dest: OPFSDirWrap): Promise<OPFSDirWrap>;
/**
* move directory, copy then remove current
*/
moveTo(dest: OPFSDirWrap): Promise<OPFSDirWrap>;
}
```
6 changes: 2 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,11 @@
"write",
"browser",
"Web",
"opfs-tools",
"tools",
"文件系统",
"文件读写",
"工具"
"文件读写"
],
"version": "0.1.1",
"version": "0.2.0",
"type": "module",
"module": "dist/opfs-tools.js",
"main": "dist/opfs-tools.umd.cjs",
Expand Down

0 comments on commit ffe5619

Please sign in to comment.