|
| 1 | +## tftp2 |
| 2 | + |
| 3 | +> simple tftp server and client in node.js |
| 4 | +
|
| 5 | +![[email protected]](https://img.shields.io/npm/v/tftp2.svg) |
| 6 | +[](https://travis-ci.org/song940/node-tftp) |
| 7 | + |
| 8 | +### Installation |
| 9 | + |
| 10 | +```bash |
| 11 | +$ npm i tftp2 |
| 12 | +``` |
| 13 | + |
| 14 | +### Example |
| 15 | + |
| 16 | +```js |
| 17 | +const tftp = require('tftp2'); |
| 18 | + |
| 19 | +const { read, write } = tftp('127.0.0.1', 6969); |
| 20 | + |
| 21 | +read('remote.txt').pipe(fs.createWriteStream('/tmp/demo.txt')); |
| 22 | + |
| 23 | +``` |
| 24 | + |
| 25 | +```js |
| 26 | +const fs = require('fs'); |
| 27 | +const tftp = require('tftp2'); |
| 28 | + |
| 29 | +const server = tftp.createServer(); |
| 30 | + |
| 31 | +server.on('get', async (req, send) => { |
| 32 | + const { filename, mode, address, port } = req; |
| 33 | + console.log('get', filename, mode, address, port); |
| 34 | + await send(fs.readFileSync(filename)); |
| 35 | +}); |
| 36 | + |
| 37 | +server.on('put', async (req, read) => { |
| 38 | + const { filename, mode, address, port } = req; |
| 39 | + console.log('put', filename, mode, address, port); |
| 40 | + const buffer = []; |
| 41 | + read(chunk => buffer.push(chunk), () => { |
| 42 | + fs.writeFileSync(filename, Buffer.concat(buffer)); |
| 43 | + }); |
| 44 | +}); |
| 45 | + |
| 46 | +``` |
| 47 | + |
| 48 | +### Contributing |
| 49 | +- Fork this Repo first |
| 50 | +- Clone your Repo |
| 51 | +- Install dependencies by `$ npm install` |
| 52 | +- Checkout a feature branch |
| 53 | +- Feel free to add your features |
| 54 | +- Make sure your features are fully tested |
| 55 | +- Publish your local branch, Open a pull request |
| 56 | +- Enjoy hacking <3 |
| 57 | + |
| 58 | +### MIT |
| 59 | + |
| 60 | +Copyright (c) 2016 Lsong <[email protected]> |
| 61 | + |
| 62 | +Permission is hereby granted, free of charge, to any person obtaining a copy |
| 63 | +of this software and associated documentation files (the "Software"), to deal |
| 64 | +in the Software without restriction, including without limitation the rights |
| 65 | +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 66 | +copies of the Software, and to permit persons to whom the Software is |
| 67 | +furnished to do so, subject to the following conditions: |
| 68 | + |
| 69 | +The above copyright notice and this permission notice shall be included in |
| 70 | +all copies or substantial portions of the Software. |
| 71 | + |
| 72 | +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 73 | +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 74 | +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 75 | +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 76 | +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 77 | +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 78 | +THE SOFTWARE. |
| 79 | + |
| 80 | + |
| 81 | +--- |
0 commit comments