Files: 4f27567900a7b5b821bccc74e95bfc96c8233159 / node_modules / pull-stream / throughs / map.js
484 bytesRaw
1 | |
2 | |
3 | function id (e) { return e } |
4 | var prop = require('../util/prop') |
5 | |
6 | module.exports = function map (mapper) { |
7 | if(!mapper) return id |
8 | mapper = prop(mapper) |
9 | return function (read) { |
10 | return function (abort, cb) { |
11 | read(abort, function (end, data) { |
12 | try { |
13 | data = !end ? mapper(data) : null |
14 | } catch (err) { |
15 | return read(err, function () { |
16 | return cb(err) |
17 | }) |
18 | } |
19 | cb(end, data) |
20 | }) |
21 | } |
22 | } |
23 | } |
24 |
Built with git-ssb-web