Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/SBoudrias/mem-fs
Simple in-memory vinyl file store.
https://github.com/SBoudrias/mem-fs
Last synced: 3 months ago
JSON representation
Simple in-memory vinyl file store.
- Host: GitHub
- URL: https://github.com/SBoudrias/mem-fs
- Owner: SBoudrias
- License: mit
- Created: 2014-10-17T04:38:48.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2024-02-26T21:25:06.000Z (4 months ago)
- Last Synced: 2024-03-24T13:43:39.469Z (3 months ago)
- Language: TypeScript
- Size: 237 KB
- Stars: 115
- Watchers: 10
- Forks: 14
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE-MIT
Lists
- awesome-stars - SBoudrias/mem-fs - Simple in-memory vinyl file store. (JavaScript)
- awesome-stars - mem-fs - memory vinyl file store. | SBoudrias | 123 | (TypeScript)
README
# mem-fs
Simple in-memory vinyl file store.
## Usage
### Loading a file
You access a file using `store#get()` method. If the file is in memory, it will be used. Otherwise, we'll load the file from the file-system.
```js
import { create } from 'mem-fs';const store = create();
store.get('/test/file.txt');
```When trying to load a file we cannot read from disk, an empty Vinyl file will be returned. The `contents` of this file will be set to `null`.
Trying to get a directory or any invalid files will also return an empty Vinyl file pointer.
### Adding/updating a file
You update file references by using `store#add()` method. This method take a `vinyl` file object as parameter.
```js
import File from 'vinyl';
import { create } from 'mem-fs';const coffeeFile = new File({
cwd: '/',
base: '/test/',
path: '/test/file.coffee',
contents: new Buffer('test = 123'),
});const store = create();
store.add(coffeeFile);
```### Iterating over the file system
Using `store#each(cb(file, index))`, you can iterate over every file stored in the file system.
### Get all files
Using `store#all()`, you can get every file stored in the file system.
### Check existence in the file system
Using `store#existsInMemory()`, you can check if the file already exists in the file system without loading it from disk.
### Stream every file stored in the file system
Using `store#stream()`, you can create a stream with every file stored in the file system.
### Pass stored files through a pipeline
`store#pipeline()` generates a new map with yielded files in transforms.
If no transform is passed, files references are updated.