# pub-src-fs

> Default file system source for pub-server and pub-generator

Latest version **3.0.0** (published 2026-02-21) · MIT license · 0 weekly downloads

## Install

```sh
npm install pub-src-fs
pnpm add pub-src-fs
yarn add pub-src-fs
bun add pub-src-fs
```

## Health

**Score 45/100 (D)** — status: stable.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

## Facts

| | |
|---|---|
| Version | 3.0.0 |
| Published | 2026-02-21 |
| First published | 2015-04-12 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 7 |
| Unpacked size | 16.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Jürgen Leschner |
| Maintainers | jldec |

## Links

- npm: https://www.npmjs.com/package/pub-src-fs
- Repository: https://github.com/jldec/pub-server-monorepo
- Homepage: https://github.com/jldec/pub-server-monorepo#readme
- Issues: https://github.com/jldec/pub-server-monorepo/issues
- npm.io page: https://npm.io/package/pub-src-fs

## Dependencies (7)

- [debug](https://npm.io/package/debug.md) 4.3.6
- [unorm](https://npm.io/package/unorm.md) ^1.6.0
- [queue4](https://npm.io/package/queue4.md) 2.0.0
- [pub-util](https://npm.io/package/pub-util.md) 4.0.0
- [minimatch](https://npm.io/package/minimatch.md) ^3.0.4
- [asyncbuilder](https://npm.io/package/asyncbuilder.md) 2.0.0
- [binary-extensions](https://npm.io/package/binary-extensions.md) ^2.2.0

## Recent versions

- 3.0.0 (latest) — 2026-02-21
- 2.2.0 — 2024-09-01
- 2.1.3 — 2022-01-16
- 2.1.2 — 2020-11-08
- 2.1.1 — 2020-07-26
- 2.1.0 — 2020-05-25
- 2.0.10 — 2020-04-25
- 2.0.9 — 2020-02-16
- 2.0.8 — 2019-07-13
- 2.0.7 — 2019-04-14
- 2.0.6 — 2019-04-06
- 2.0.5 — 2019-03-31
- 2.0.3 — 2019-02-10
- 2.0.2 — 2019-02-10
- 2.0.1 — 2019-02-02
- … 22 more at https://npm.io/package/pub-src-fs/versions

## README

# pub-src-fs

Default file system source for pub-server and pub-generator

* provides `get()` and `put()` for bulk reads and writes
* globs and descends directories
* assumes that all files with non-binary extensions are utf-8 text

## src(options)

```javascript
var src = require('pub-src-fs');

// instantiate source on path
// options become properties of source
var source = src( { path:'.', glob:'**/*.js', depth:2, writable:true } );

source.get(function(err, files) {
  if (err) return console.log(err);
  console.log(_.pluck(files, 'path'));
});

```

### source.path
- recurses directories starting with `path`
- omits any directories starting with '.'
- results will not include the path, just a /

### source.glob
- `glob` is a [node-glob](https://github.com/isaacs/node-glob) pattern
- in order to support recursive descent on other systems (like github) this implementation does not use the glob library to walk directories
- instead it walks directories and then calls [minimatch](https://github.com/isaacs/minimatch) to test the files in those directories.
- because `path` is used as the root for globbing, globstars in the middle of the pattern are unlikely

### source.depth
- `depth` limits the depth of tree traversal when there is globstar
- this is useful for avoiding symlink cycles and improving performance

### source.writable
- required true for successful .put()

### source.writeOnly
- disables reading with .get()

### source.dirsFirst
- if `dirsFirst` is true, entries within each directory will be returned with directories before files instead of the default (files first)

### source.dirsSame
- if `dirsSame` is true, directories and files sort together (overrides dirsFirst)

### source.get(cb)
- `get()` fetches all matching files in one async operation
- the result is an array of file objects each with a `path:` and a `text:` property (for non-binary files), or a `buffer:` property (for binary files)
- the array is sorted alphabetically by path
- results do not include directories, but do include files in subdirectories
- if the source is writable, `get()` is atomic with respect to `put()` or other `source.get()` operations

```javascript
[ { path: '/fs-base.js',
    text: '...' },
  { path: '/pub-src-fs.js',
    text: '...' } ]
```

### source.put(files, cb)
- `put()` does nothing unless `writable` is set on the source
- it writes an array of file objects back to the file system overwriting existing files
- there is no partial file write but the array may contain a subset of the files read via `get()`
- `put()` is atomic with respect to `source.get()` or other `source.put()` operations
- `put()` tries to avoid file corruption by writing to a temp location and then renaming files
- `put()` returns an array of the paths written

```javascript
source.put(files, function(err, result) {
  if (err) return console.log(err);
  console.log(result);
});
```

---
_Source: https://npm.io/package/pub-src-fs · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
