@takeshape/streams 9.80.3 → 9.81.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -3,9 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
-
7
6
  var _streams = require("./streams");
8
-
9
7
  Object.keys(_streams).forEach(function (key) {
10
8
  if (key === "default" || key === "__esModule") return;
11
9
  if (key in exports && exports[key] === _streams[key]) return;
package/dist/streams.js CHANGED
@@ -13,32 +13,21 @@ exports.readStreamToBuffer = readStreamToBuffer;
13
13
  exports.readableFromArray = void 0;
14
14
  exports.streamToPromise = streamToPromise;
15
15
  exports.tee = void 0;
16
-
17
16
  var _stream = require("stream");
18
-
19
17
  var _bluebird = _interopRequireDefault(require("bluebird"));
20
-
21
18
  var _pQueue = _interopRequireDefault(require("p-queue"));
22
-
23
19
  var _isStream = _interopRequireDefault(require("is-stream"));
24
-
25
20
  var _through = _interopRequireDefault(require("through2"));
26
-
27
21
  var _pump = _interopRequireDefault(require("pump"));
28
-
29
22
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
30
-
31
23
  const pump = _bluebird.default.promisify(_pump.default);
32
-
33
24
  exports.pump = pump;
34
-
35
25
  async function streamToPromise(stream) {
36
26
  return new Promise((resolve, reject) => {
37
27
  const doneEvent = _isStream.default.writable(stream) ? 'finish' : 'end';
38
28
  stream.on('error', reject).on(doneEvent, resolve);
39
29
  });
40
30
  }
41
-
42
31
  function createTransform(transform) {
43
32
  return _through.default.obj(function (content, _, callback) {
44
33
  try {
@@ -49,7 +38,6 @@ function createTransform(transform) {
49
38
  }
50
39
  });
51
40
  }
52
-
53
41
  function createAsyncTransform(transform) {
54
42
  return _through.default.obj(function (content, _, callback) {
55
43
  try {
@@ -62,65 +50,53 @@ function createAsyncTransform(transform) {
62
50
  }
63
51
  });
64
52
  }
65
-
66
53
  function createFilter(predicate) {
67
54
  return _through.default.obj(function (content, _, callback) {
68
55
  try {
69
56
  if (predicate(content)) {
70
57
  this.push(content);
71
58
  }
72
-
73
59
  callback();
74
60
  } catch (e) {
75
61
  callback(e);
76
62
  }
77
63
  });
78
64
  }
79
-
80
65
  const createAccumulator = accumulator => _through.default.obj(function (item, _, cb) {
81
66
  accumulator(item);
82
67
  cb(null, item);
83
68
  });
84
-
85
69
  exports.createAccumulator = createAccumulator;
86
-
87
70
  const createAsyncWritable = (write, concurrency = 16) => {
88
71
  const queue = new _pQueue.default({
89
72
  concurrency
90
73
  });
91
74
  return new _stream.Writable({
92
75
  objectMode: true,
93
-
94
76
  write(data, _, cb) {
95
77
  queue.add(async () => write(data)).catch(error => this.emit('error', error));
96
78
  cb();
97
79
  },
98
-
99
80
  final(cb) {
100
81
  void queue.onIdle().then(() => {
101
82
  cb();
102
83
  });
103
84
  }
104
-
105
85
  });
106
86
  };
107
-
108
87
  exports.createAsyncWritable = createAsyncWritable;
109
-
110
88
  const tee = (...args) => {
111
89
  const first = args[0];
112
90
  const streams = Array.isArray(first) ? first : args;
113
91
  const donePromises = streams.map(streamToPromise);
114
92
  return new _stream.Writable({
115
93
  objectMode: true,
116
-
117
94
  write(data, _, callback) {
118
95
  void Promise.all(streams.map(stream => stream.write(data) || _bluebird.default.fromCallback(cb => stream.once('drain', cb)) // If .write() => false buffer is full, start promise to wait for drain event
119
96
  )).then(() => {
120
97
  callback();
121
98
  });
122
99
  },
123
-
124
100
  final(callback) {
125
101
  streams.forEach(stream => {
126
102
  stream.end();
@@ -129,43 +105,32 @@ const tee = (...args) => {
129
105
  callback();
130
106
  });
131
107
  }
132
-
133
108
  });
134
109
  };
135
-
136
110
  exports.tee = tee;
137
-
138
111
  const readableFromArray = (array, options) => {
139
112
  let index = 0;
140
113
  return new _stream.Readable({
141
114
  objectMode: true,
142
-
143
115
  read() {
144
116
  this.push(index < array.length ? array[index] : null);
145
117
  index++;
146
118
  },
147
-
148
119
  ...options
149
120
  });
150
121
  };
151
-
152
122
  exports.readableFromArray = readableFromArray;
153
-
154
123
  const collectStreamIntoArray = (array = [], options = {}) => new _stream.Writable({
155
124
  objectMode: true,
156
-
157
125
  writev(chunks, cb) {
158
126
  chunks.forEach(({
159
127
  chunk
160
128
  }) => array.push(chunk));
161
129
  cb(null);
162
130
  },
163
-
164
131
  ...options
165
132
  });
166
-
167
133
  exports.collectStreamIntoArray = collectStreamIntoArray;
168
-
169
134
  async function readStreamToBuffer(stream) {
170
135
  const chunks = [];
171
136
  const writeStream = new _stream.PassThrough();
package/es/streams.js CHANGED
@@ -39,7 +39,6 @@ export function createFilter(predicate) {
39
39
  if (predicate(content)) {
40
40
  this.push(content);
41
41
  }
42
-
43
42
  callback();
44
43
  } catch (e) {
45
44
  callback(e);
@@ -56,18 +55,15 @@ export const createAsyncWritable = (write, concurrency = 16) => {
56
55
  });
57
56
  return new Writable({
58
57
  objectMode: true,
59
-
60
58
  write(data, _, cb) {
61
59
  queue.add(async () => write(data)).catch(error => this.emit('error', error));
62
60
  cb();
63
61
  },
64
-
65
62
  final(cb) {
66
63
  void queue.onIdle().then(() => {
67
64
  cb();
68
65
  });
69
66
  }
70
-
71
67
  });
72
68
  };
73
69
  export const tee = (...args) => {
@@ -76,14 +72,12 @@ export const tee = (...args) => {
76
72
  const donePromises = streams.map(streamToPromise);
77
73
  return new Writable({
78
74
  objectMode: true,
79
-
80
75
  write(data, _, callback) {
81
76
  void Promise.all(streams.map(stream => stream.write(data) || BBPromise.fromCallback(cb => stream.once('drain', cb)) // If .write() => false buffer is full, start promise to wait for drain event
82
77
  )).then(() => {
83
78
  callback();
84
79
  });
85
80
  },
86
-
87
81
  final(callback) {
88
82
  streams.forEach(stream => {
89
83
  stream.end();
@@ -92,32 +86,27 @@ export const tee = (...args) => {
92
86
  callback();
93
87
  });
94
88
  }
95
-
96
89
  });
97
90
  };
98
91
  export const readableFromArray = (array, options) => {
99
92
  let index = 0;
100
93
  return new Readable({
101
94
  objectMode: true,
102
-
103
95
  read() {
104
96
  this.push(index < array.length ? array[index] : null);
105
97
  index++;
106
98
  },
107
-
108
99
  ...options
109
100
  });
110
101
  };
111
102
  export const collectStreamIntoArray = (array = [], options = {}) => new Writable({
112
103
  objectMode: true,
113
-
114
104
  writev(chunks, cb) {
115
105
  chunks.forEach(({
116
106
  chunk
117
107
  }) => array.push(chunk));
118
108
  cb(null);
119
109
  },
120
-
121
110
  ...options
122
111
  });
123
112
  export async function readStreamToBuffer(stream) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@takeshape/streams",
3
- "version": "9.80.3",
3
+ "version": "9.81.0",
4
4
  "description": "Stream helpers",
5
5
  "homepage": "https://www.takeshape.io",
6
6
  "repository": {
@@ -27,7 +27,7 @@
27
27
  "@types/bluebird": "^3.5.32",
28
28
  "@types/pump": "^1.1.0",
29
29
  "@types/through2": "^2.0.36",
30
- "@takeshape/typescript-jest-junit-reporter": "9.80.3"
30
+ "@takeshape/typescript-jest-junit-reporter": "9.81.0"
31
31
  },
32
32
  "engines": {
33
33
  "node": ">=16"