File tree 2 files changed +22
-0
lines changed
2 files changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -25,6 +25,11 @@ You can also initialize a `RAM` instance with a `Buffer`:
25
25
const file = new RAM (Buffer .from (' hello world' ))
26
26
```
27
27
28
+ If you want to mimick a folder on disk, you can use ` const createRAM = RAM.resuable() ` .
29
+
30
+ This stores the created ram instances, ie ` ram = createRAM(name) ` in a map so they can be reopened
31
+ with the same state, similar to working with files, but still backed by ram.
32
+
28
33
## License
29
34
30
35
MIT
Original file line number Diff line number Diff line change @@ -23,6 +23,23 @@ module.exports = class RAM extends RandomAccess {
23
23
if ( opts . buffer ) this . buffers . push ( opts . buffer )
24
24
}
25
25
26
+ static reusable ( ) {
27
+ const all = new Map ( )
28
+ const RAM = this
29
+
30
+ return function createStorage ( name ) {
31
+ const existing = all . get ( name )
32
+ const ram = existing ? existing . clone ( ) : new RAM ( )
33
+
34
+ all . set ( name , ram )
35
+ ram . on ( 'unlink' , function ( ) {
36
+ if ( all . get ( name ) === ram ) all . delete ( name )
37
+ } )
38
+
39
+ return ram
40
+ }
41
+ }
42
+
26
43
_stat ( req ) {
27
44
const st = {
28
45
size : this . length ,
You can’t perform that action at this time.
0 commit comments