-
-
Notifications
You must be signed in to change notification settings - Fork 130
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: 🎸 explose FSA from index file
- Loading branch information
Showing
2 changed files
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import {nodeToFsa} from '..'; | ||
import { IFsWithVolume, memfs } from '../..'; | ||
import { maybe } from './util'; | ||
|
||
maybe('scenarios', () => { | ||
test('can init FSA from an arbitrary FS folder and execute operations', async () => { | ||
const fs = memfs({ | ||
'/tmp': null, | ||
'/etc': null, | ||
'/bin': null, | ||
'/Users/kasper/Documents/shopping-list.txt': 'Milk, Eggs, Bread', | ||
}) as IFsWithVolume; | ||
const dir = nodeToFsa(fs, '/Users/kasper/Documents'); | ||
const shoppingListFile = await dir.getFileHandle('shopping-list.txt'); | ||
const shoppingList = await shoppingListFile.getFile(); | ||
expect(await shoppingList.text()).toBe('Milk, Eggs, Bread'); | ||
const backupsDir = await dir.getDirectoryHandle('backups', { create: true }); | ||
const backupFile = await backupsDir.getFileHandle('shopping-list.txt', { create: true }); | ||
const writable = await backupFile.createWritable(); | ||
await writable.write(await shoppingList.arrayBuffer()); | ||
await writable.close(); | ||
const logsFileHandle = await dir.getFileHandle('logs.csv', { create: true }); | ||
const logsWritable = await logsFileHandle.createWritable(); | ||
await logsWritable.write('timestamp,level,message\n'); | ||
await logsWritable.write({type: 'write', data: '2021-01-01T00:00:00Z,INFO,Hello World\n'}); | ||
await logsWritable.close(); | ||
expect(fs.__vol.toJSON()).toEqual({ | ||
'/tmp': null, | ||
'/etc': null, | ||
'/bin': null, | ||
'/Users/kasper/Documents/shopping-list.txt': 'Milk, Eggs, Bread', | ||
'/Users/kasper/Documents/backups/shopping-list.txt': 'Milk, Eggs, Bread', | ||
'/Users/kasper/Documents/logs.csv': 'timestamp,level,message\n2021-01-01T00:00:00Z,INFO,Hello World\n' | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import {NodeFileSystemDirectoryHandle} from './NodeFileSystemDirectoryHandle'; | ||
import {NodeFsaContext, NodeFsaFs} from './types'; | ||
|
||
export * from './types'; | ||
export * from './NodeFileSystemHandle'; | ||
export * from './NodeFileSystemDirectoryHandle'; | ||
export * from './NodeFileSystemFileHandle'; | ||
|
||
export const nodeToFsa = (fs: NodeFsaFs, dirPath: string, ctx?: Partial<NodeFsaContext>): NodeFileSystemDirectoryHandle => { | ||
return new NodeFileSystemDirectoryHandle(fs, dirPath, ctx); | ||
}; |