-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
dev(pkg::core): add a memory access model
- Loading branch information
1 parent
ec05968
commit da9586c
Showing
5 changed files
with
63 additions
and
3 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
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
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,54 @@ | ||
import { FsAccessModel } from '../internal.types.mjs'; | ||
import { WritableAccessModel } from './index.mjs'; | ||
|
||
export class MemoryAccessModel implements FsAccessModel, WritableAccessModel { | ||
mTimes: Map<string, Date | undefined> = new Map(); | ||
mData: Map<string, Uint8Array | undefined> = new Map(); | ||
constructor() {} | ||
|
||
reset() { | ||
this.mTimes.clear(); | ||
this.mData.clear(); | ||
} | ||
|
||
insertFile(path: string, data: Uint8Array, mtime: Date) { | ||
this.mTimes.set(path, mtime); | ||
this.mData.set(path, data); | ||
} | ||
|
||
removeFile(path: string) { | ||
this.mTimes.delete(path); | ||
this.mData.delete(path); | ||
} | ||
|
||
getMTime(path: string): Date | undefined { | ||
if (!path.startsWith('/@memory/')) { | ||
return undefined; | ||
} | ||
|
||
if (this.mTimes.has(path)) { | ||
return this.mTimes.get(path); | ||
} | ||
return undefined; | ||
} | ||
|
||
isFile(): boolean | undefined { | ||
return true; | ||
} | ||
|
||
getRealPath(path: string): string | undefined { | ||
return path; | ||
} | ||
|
||
readAll(path: string): Uint8Array | undefined { | ||
if (!path.startsWith('/@memory/')) { | ||
return undefined; | ||
} | ||
|
||
if (this.mData.has(path)) { | ||
return this.mData.get(path); | ||
} | ||
|
||
return undefined; | ||
} | ||
} |
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
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