|
Last change
on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 11 days ago |
|
Fix frontend appearance
|
-
Property mode
set to
100644
|
|
File size:
1.2 KB
|
| Line | |
|---|
| 1 | 'use strict'
|
|---|
| 2 |
|
|---|
| 3 | const stream = require('stream')
|
|---|
| 4 | const check = require('check-types')
|
|---|
| 5 | const parse = require('./parse')
|
|---|
| 6 |
|
|---|
| 7 | module.exports = unpipe
|
|---|
| 8 |
|
|---|
| 9 | /**
|
|---|
| 10 | * Public function `unpipe`.
|
|---|
| 11 | *
|
|---|
| 12 | * Returns a writeable stream that can be passed to stream.pipe, then parses JSON
|
|---|
| 13 | * data read from the stream. If there are no errors, the callback is invoked with
|
|---|
| 14 | * the result as the second argument. If errors occur, the first error is passed to
|
|---|
| 15 | * the callback as the first argument.
|
|---|
| 16 | *
|
|---|
| 17 | * @param callback: Function that will be called after parsing is complete.
|
|---|
| 18 | *
|
|---|
| 19 | * @option reviver: Transformation function, invoked depth-first.
|
|---|
| 20 | *
|
|---|
| 21 | * @option discard: The number of characters to process before discarding them
|
|---|
| 22 | * to save memory. The default value is `1048576`.
|
|---|
| 23 | *
|
|---|
| 24 | * @option yieldRate: The number of data items to process per timeslice,
|
|---|
| 25 | * default is 16384.
|
|---|
| 26 | **/
|
|---|
| 27 | function unpipe (callback, options) {
|
|---|
| 28 | check.assert.function(callback, 'Invalid callback argument')
|
|---|
| 29 |
|
|---|
| 30 | const jsonstream = new stream.PassThrough()
|
|---|
| 31 |
|
|---|
| 32 | parse(jsonstream, { ...options, ndjson: false })
|
|---|
| 33 | .then(data => callback(null, data))
|
|---|
| 34 | .catch(error => callback(error))
|
|---|
| 35 |
|
|---|
| 36 | return jsonstream
|
|---|
| 37 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.