debian/tests/test_modules/from2-string/index.js
raw| 1 | const assert = require('assert') |
| 2 | const from = require('from2') |
| 3 | |
| 4 | module.exports = fromString |
| 5 | |
| 6 | // create a stream from a string |
| 7 | // str -> stream |
| 8 | function fromString (string) { |
| 9 | assert.equal(typeof string, 'string') |
| 10 | |
| 11 | return from(function (size, next) { |
| 12 | if (string.length <= 0) return this.push(null) |
| 13 | |
| 14 | const chunk = string.slice(0, size) |
| 15 | string = string.slice(size) |
| 16 | |
| 17 | next(null, chunk) |
| 18 | }) |
| 19 | } |