|
| 1 | +# 🇭TTP 🇫ilesystem |
| 2 | + |
| 3 | +[![Standard JS][standard-src]][standard-href] |
| 4 | +[![david dm][david-src]][david-href] |
| 5 | +[![codecov][codecov-src]][codecov-href] |
| 6 | +[![circleci][circleci-src]][circleci-href] |
| 7 | + |
| 8 | +[![npm version][npm-v-src]][npm-v-href] |
| 9 | +[![npm downloads][npm-dt-src]][npm-dt-href] |
| 10 | +[![package phobia][packagephobia-src]][packagephobia-href] |
| 11 | + |
| 12 | +### **NOTE** This module is under development and not ready for any production use! |
| 13 | + |
| 14 | +Expose filesystem via HTTP and access it from the other side! |
| 15 | + |
| 16 | +This module works best with [memory-fs](https://github.com/webpack/memory-fs). |
| 17 | + |
| 18 | +## Install |
| 19 | + |
| 20 | +Install package: |
| 21 | + |
| 22 | +```bash |
| 23 | +yarn add httpfs |
| 24 | +``` |
| 25 | + |
| 26 | +OR |
| 27 | + |
| 28 | +```bash |
| 29 | +npm install httpfs |
| 30 | +``` |
| 31 | + |
| 32 | +## Server |
| 33 | + |
| 34 | +Serving real fs is not a good idea. In this example we serve a virtual filesystem. |
| 35 | + |
| 36 | +```js |
| 37 | +const HTTPFSMiddleware = require('httpfs/lib/middleware') |
| 38 | +const express = require('express') |
| 39 | +const MFS = require('memory-fs') |
| 40 | + |
| 41 | +// Create a new express app listening on port 8080 |
| 42 | +const app = express() |
| 43 | +app.listen(8080) |
| 44 | + |
| 45 | +// Create a new Virtual FileSystem with a test file |
| 46 | +const mfs = new MFS() |
| 47 | +mfs.mkdirpSync('/test') |
| 48 | +mfs.writeFileSync('/test/file.txt', 'Works!') |
| 49 | + |
| 50 | +// Create and register fs middleware |
| 51 | +app.use('/mfs', HTTPFSMiddleware(mfs)) |
| 52 | +``` |
| 53 | + |
| 54 | +You can now browse filesystem via a normal browser via http://localhost:8080/mfs/ |
| 55 | + |
| 56 | +## Client |
| 57 | + |
| 58 | +Supported methods: |
| 59 | + |
| 60 | +- `exists(path): Promise<Boolean>` |
| 61 | +- `readFile(path): Promise<String>` |
| 62 | + |
| 63 | +```js |
| 64 | +const HTTPFSAClient = require('httpfs/lib/client') |
| 65 | + |
| 66 | +const fs = new HTTPFSAClient({ |
| 67 | + endpoint: 'http://localhost:8080/mfs' |
| 68 | +}) |
| 69 | + |
| 70 | +fs.readFile('/test/file.txt').then((contents) => { |
| 71 | + console.log('File contents:', contents) |
| 72 | +}) |
| 73 | +``` |
| 74 | + |
| 75 | +### Options |
| 76 | + |
| 77 | +- `endpoint`: HTTP Endpoint of server |
| 78 | +- `maxAge`: Time for cache |
| 79 | + |
| 80 | +## License |
| 81 | + |
| 82 | +MIT. Made with 💖 |
| 83 | + |
| 84 | +<!-- Refs --> |
| 85 | +[standard-src]: https://flat.badgen.net/badge/code%20style/standard/green |
| 86 | +[standard-href]: https://standardjs.com |
| 87 | + |
| 88 | +[npm-v-src]: https://flat.badgen.net/npm/v/httpfs/latest |
| 89 | +[npm-v-href]: https://npmjs.com/package/httpfs |
| 90 | + |
| 91 | +[npm-dt-src]: https://flat.badgen.net/npm/dt/httpfs |
| 92 | +[npm-dt-href]: https://npmjs.com/package/httpfs |
| 93 | + |
| 94 | +[packagephobia-src]: https://flat.badgen.net/packagephobia/install/httpfs |
| 95 | +[packagephobia-href]: https://packagephobia.now.sh/result?p=httpfs |
| 96 | + |
| 97 | +[david-src]: https://flat.badgen.net/david/dep/jsless/httpfs |
| 98 | +[david-href]: https://david-dm.org/jsless/httpfs |
| 99 | + |
| 100 | +[codecov-src]: https://flat.badgen.net/codecov/c/github/jsless/httpfs/master |
| 101 | +[codecov-href]: https://codecov.io/gh/jsless/httpfs |
| 102 | + |
| 103 | +[circleci-src]: https://flat.badgen.net/circleci/github/jsless/httpfs/master |
| 104 | +[circleci-href]: https://circleci.com/gh/jsless/httpfs |
0 commit comments