
Product
Introducing Socket Firewall Enterprise: Flexible, Configurable Protection for Modern Package Ecosystems
Socket Firewall Enterprise is now available with flexible deployment, configurable policies, and expanded language support.
A filesystem utility, supporting batch & in-memory operations.
npm install --save buffs
Every API works both on the real filesystem and in-memory filesystems created by createFs.
copyCopy a file or directory from the source to the target filesystem recursively.
Type: (source: IFS, target: IFS, sourcePath: string, targetPath?: string, options?: CopyOptions) => void
import fs from 'fs'
import process from 'process'
import { copy, createFs } from 'buffs'
// Create files using in-memory filesystem
const { fs: source } = createFs({
'/a.txt': 'a',
'/b/b.txt': 'b',
})
// Copy all files from source to your current directory
copy(source, fs, '/', process.cwd())
createFsCreate an in-memory filesystem.
This is a wrapper around memfs.
Type: (json: DirectoryJSON = {}, cwd?: string) => { volume: VolumeType; fs: IFS }
import { createFs } from 'buffs'
// Create files using in-memory filesystem
const fs = createFs({
'/a.txt': 'a',
'/b/b.txt': 'b',
'/c': null, // Empty directory
})
describeCreate a description of all files in the source filesystem.
Type: (source: IFS, filePath: string) => string
import { describe, createFs } from 'buffs'
// Create files using in-memory filesystem
const fs = createFs({
'/a.txt': 'a',
'/b/b.txt': 'b',
})
const description = describe(fs, '/')
console.log(description)
// ├── a.txt
// └── b / b.txt
describeComparisonCreate a description of all files in the "updated" source filesystem, relative to the state of the "original" target filesystem.
Type: (source: IFS, target: IFS, filePath: string, { colorize?: boolean }): string
import { describeComparison, createFs } from 'buffs'
const source = createFs({
'/a.txt': 'a',
'/b/b.txt': 'b',
})
const target = createFs({
'/b/b.txt': 'b',
})
const description = describeComparison(source, target, '/', { colorize: true })
console.log(description)
// ├── a.txt (printed in green, since it was "added")
// └── b / b.txt
findFind files and directories using an include predicate function.
If an exclude function option is passed, returning true will skip any file and its children, regardless of what include returned.
Type: (source: IFS, searchPath: string, options: FindOptions) => string[]
import { createFs, find } from 'buffs'
// Create files using in-memory filesystem
const fs = createFs({
'/a.txt': 'a',
'/b/b.txt': 'b',
})
const files = find(fs, '/', {
include: (file) => file.endsWith('.txt'),
})
console.log(files)
// ['a.txt', 'b/b.txt']
matchFind files and directories using glob (https://github.com/micromatch/micromatch) patterns.
If an excludePatterns function option is passed, returning true will skip any file and its children, regardless of what include returned.
Type: (source: IFS, searchPath: string, options: MatchOptions) => string[]
import { createFs, match } from 'buffs'
// Create files using in-memory filesystem
const fs = createFs({
'/a.txt': 'a',
'/b/b.txt': 'b',
})
const files = match(fs, '/', { includePatterns: ['**/*.txt'] })
console.log(files)
// ['a.txt', 'b/b.txt']
toJSONConvert a directory and all its files, recursively, to a JSON dictionary.
Type: (source: IFS, rootPath: string) => DirectoryJSON
import { createFs, match } from 'buffs'
// Create files using in-memory filesystem
const fs = createFs({
'/a.txt': 'a',
'/b/b.txt': 'b',
})
const json = toJSON(fs)
console.log(json)
// { '/a.txt': 'a', '/b/b.txt': 'b' }
visitTraverse a directory recursively, calling an optional onEnter and onLeave function for each file and directory.
From onEnter:
undefined to continue"skip" to skip any children of that directory and the subsequent onLeave"stop" to end traversalFrom onLeave:
undefined to continue"stop" to end traversalType: (source: IFS, rootPath: string, options: VisitOptions) => void
import path from 'path'
import { createFs, visit } from 'buffs'
// Create files using in-memory filesystem
const fs = createFs({
'/a.txt': 'a',
'/b/b.txt': 'b',
})
const allFiles = []
const files = visit(fs, '/', {
onEnter: (file) => {
allFiles.push(path.join('/', file))
},
})
console.log(allFiles)
// ['/', '/a.txt', '/b', '/b/b.txt']
FAQs
A filesystem utility, supporting batch & in-memory operations.
We found that buffs demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Product
Socket Firewall Enterprise is now available with flexible deployment, configurable policies, and expanded language support.

Security News
Open source dashboard CNAPulse tracks CVE Numbering Authorities’ publishing activity, highlighting trends and transparency across the CVE ecosystem.

Product
Detect malware, unsafe data flows, and license issues in GitHub Actions with Socket’s new workflow scanning support.