| Conditions | 4 |
| Paths | 4 |
| Total Lines | 23 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | const fs = require('fs') |
||
| 5 | module.exports = (input, callback) => { |
||
| 6 | if (typeof input === 'string') { |
||
| 7 | // Input as file |
||
| 8 | const path = join(__dirname, '../', input) |
||
| 9 | if (!fs.existsSync(path)) { |
||
| 10 | console.error(`Cannot read file ${path}`) |
||
| 11 | return |
||
| 12 | } |
||
| 13 | const html = fs.readFileSync(path, 'utf8') |
||
| 14 | callback(html) |
||
| 15 | } else if (input instanceof Readable) { |
||
| 16 | // Input as stream |
||
| 17 | input.on('data', chunk => { |
||
| 18 | callback(chunk.toString()) |
||
| 19 | }) |
||
| 20 | input.on('error', err => { |
||
| 21 | console.error(err) |
||
| 22 | }) |
||
| 23 | } else { |
||
| 24 | // Unknown input |
||
| 25 | console.error('Invalid Input') |
||
| 26 | } |
||
| 27 | } |
||
| 28 |