/** * Flatten the given arrays into a new array * * @param {Array<Array<T>>} arrays * @returns {Array<T>} * @template T */ function flatten(arrays) { return [].concat.apply([], arrays) }
const bufferStream = stream => { const chunks = []; return new Promise((resolve, reject) => { stream.on('data', chunk => chunks.push(Buffer.from(chunk))); stream.on('error', reject); stream.on('end', () => resolve(Buffer.concat(chunks).toString('utf8'))); }); }
Promise.all( globs.map(g => glob(g.pattern, g.options)) ).then(all => getUniques([].concat.apply([], all)))
export function serialize(body) { if (supportsBuffer && body) { let buffer; if (Buffer.isBuffer(body)) { buffer = body; } else if (Array.isArray(body) && body.some(c => Buffer.isBuffer(c))) { // Body is a chunked array const chunks = body.map(c => Buffer.from(c)); buffer = Buffer.concat(chunks); } else if (`${body}` === '[object ArrayBuffer]') { buffer = Buffer.from(body); } else if (supportsArrayBuffer && ArrayBuffer.isView(body)) { buffer = Buffer.from(body.buffer, body.byteOffset, body.byteLength); } if (Buffer.isBuffer(buffer)) { return buffer.toString('hex'); } } return body; }
/** * Merge an array of strings into a single string or concat an array * of buffers into a single buffer. * * @export * @param {string[] | Buffer[]} [chunks] * @returns {string | Buffer} */ export default function mergeChunks(chunks) { if (!chunks || chunks.length === 0) { return Buffer.alloc(0); } // We assume that all chunks are Buffer objects if the first is buffer object. if (!Buffer.isBuffer(chunks[0])) { // When the chunks are not buffers we assume that they are strings. return chunks.join(''); } // Merge all the buffers into a single Buffer object. return Buffer.concat(chunks); }
export default function getBufferFromStream(stream) { return new Promise(resolve => { const chunks = []; stream.on('data', chunk => { chunks.push(chunk); }); stream.on('end', () => { resolve(Buffer.concat(chunks)); }); }); }
); const url = getUrlFromOptions(parsedArguments.options); const requestBodyBuffer = Buffer.concat(req.requestBodyBuffers); const body = isUtf8Representable(requestBodyBuffer) ? requestBodyBuffer.toString('utf8')
const groups = [].concat.apply([], responses)
[].concat.apply([], tagNames.map(function(tag) { var collection = node.getElementsByTagName(tag); return Array.isArray(collection) ? collection : Array.from(collection); }))
// ------------------------------ Append ------------------------------ append(appendBuffer) { if (this.buffer) { this.buffer = Buffer.concat([this.buffer, appendBuffer]); } else { this.buffer = appendBuffer; } }
export default function getBufferFromStream(stream) { return new Promise(resolve => { const chunks = []; stream.on('data', chunk => { chunks.push(chunk); }); stream.on('end', () => { resolve(Buffer.concat(chunks)); }); }); }
Promise.all( globs.map(g => glob(g.pattern, g.options)) ).then(all => getUniques([].concat.apply([], all)))
/** * Merge an array of strings into a single string or concat an array * of buffers into a single buffer. * * @export * @param {string[] | Buffer[]} [chunks] * @returns {string | Buffer} */ export default function mergeChunks(chunks) { if (!chunks || chunks.length === 0) { return Buffer.alloc(0); } // We assume that all chunks are Buffer objects if the first is buffer object. if (!Buffer.isBuffer(chunks[0])) { // When the chunks are not buffers we assume that they are strings. return chunks.join(''); } // Merge all the buffers into a single Buffer object. return Buffer.concat(chunks); }
export function serialize(body) { if (supportsBuffer && body) { let buffer; if (Buffer.isBuffer(body)) { buffer = body; } else if (Array.isArray(body) && body.some(c => Buffer.isBuffer(c))) { // Body is a chunked array const chunks = body.map(c => Buffer.from(c)); buffer = Buffer.concat(chunks); } else if (`${body}` === '[object ArrayBuffer]') { buffer = Buffer.from(body); } else if (supportsArrayBuffer && ArrayBuffer.isView(body)) { buffer = Buffer.from(body.buffer, body.byteOffset, body.byteLength); } if (Buffer.isBuffer(buffer)) { return buffer.toString('hex'); } } return body; }
); const url = getUrlFromOptions(parsedArguments.options); const requestBodyBuffer = Buffer.concat(req.requestBodyBuffers); const body = isUtf8Representable(requestBodyBuffer) ? requestBodyBuffer.toString('utf8')