describe('child_process', function() { it('should works in child_process', cb => { let cmd = fork(path.resolve(__dirname, './support/child_process.js'), [], { silent: true, }); let stdout = ''; let stderr = ''; cmd.stdout.on('data', buf => { let data = buf.toString(); stdout += data; if (data.includes('color')) cmd.stdin.write('orange\n'); }); cmd.stderr.on('data', buf => { stderr += buf.toString(); }); cmd.on('close', () => { assert(!stderr); assert(stdout.includes('color: \'orange\'')); cb(); }); }); });
function blocks(filepath) { let str = fs.readFileSync(filepath); return new Promise(async(resolve, reject) => { let comment = tokenize(str.toString(), { stripStars: false }); let choices = toChoices(comment.examples); let example;
readFloat() { this.check(4); let r = this.buf.readFloatLE(this.pos); this.pos += 4; return r; }
writeBytes(bytes: Array<number>) { let len = bytes.length; this.ensureCapacity(len + 4); this.writeInt(len); for (let i = 0; i < len; i++) { this.buf.writeUInt8(bytes[i], this.count++); } }
let isHttp = function (data: Buffer) { let head = data.toString('utf8', 0, 4); for (let i = 0, l = HTTP_METHODS.length; i < l; i++) { if (head.indexOf(HTTP_METHODS[i]) === 0) { return true; } } return false; }
writeDouble(v: number) { this.ensureCapacity(8); this.buf.writeDoubleLE(v, this.count); this.count += 8; }
ensureCapacity(len: number) { let minCapacity = this.count + len; if (minCapacity > this.buf.length) { this.grow(minCapacity); // double grow } }
write(data: string, offset: number, len: number) { this.ensureCapacity(len); this.buf.write(data, offset, len); this.count += len; }
readUShort() { this.check(2); let r = this.buf.readUInt16LE(this.pos); this.pos += 2; return r; }
writeInt(v: number) { this.ensureCapacity(4); this.buf.writeInt32LE(v, this.count); this.count += 4; }
readShort() { this.check(2); let r = this.buf.readInt16LE(this.pos); this.pos += 2; return r; }
writeFloat(v: number) { this.ensureCapacity(4); this.buf.writeFloatLE(v, this.count); this.count += 4; }
readFloat() { this.check(4); let r = this.buf.readFloatLE(this.pos); this.pos += 4; return r; }
writeDouble(v: number) { this.ensureCapacity(8); this.buf.writeDoubleLE(v, this.count); this.count += 8; }
write(data: string, offset: number, len: number) { this.ensureCapacity(len); this.buf.write(data, offset, len); this.count += len; }