|
|
@@ -1,6 +1,6 @@
|
|
|
'use strict';
|
|
|
|
|
|
-import {Writable} from 'stream';
|
|
|
+import {Readable, Writable} from 'stream';
|
|
|
|
|
|
export const streamToArray = array =>
|
|
|
new Writable({
|
|
|
@@ -11,6 +11,23 @@ export const streamToArray = array =>
|
|
|
}
|
|
|
});
|
|
|
|
|
|
+export const readString = (string, quant) => new Readable({
|
|
|
+ read() {
|
|
|
+ if (isNaN(quant)) {
|
|
|
+ this.push(string);
|
|
|
+ } else if (string instanceof Buffer) {
|
|
|
+ for (let i = 0; i < string.length; i += quant) {
|
|
|
+ this.push(string.slice(i, i + quant));
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ for (let i = 0; i < string.length; i += quant) {
|
|
|
+ this.push(string.substr(i, quant));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ this.push(null);
|
|
|
+ }
|
|
|
+});
|
|
|
+
|
|
|
export const delay = (fn, ms = 20) => async (...args) =>
|
|
|
new Promise((resolve, reject) => {
|
|
|
setTimeout(() => {
|