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;
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; }
getCache():{dictVersion:string,protoVersion:string,dict:any,protos:any}{ try{ return JSON.parse(fs.readFileSync(__dirname+'/cache.tmp').toString())as any; }catch (err){ return null; } }
readString() { let len = this.readInt(); this.check(len); let r = this.buf.toString('utf8', this.pos, this.pos + len); this.pos += len; return r; }
encodeStr(key: string, msg: object, code: string) { code = code || 'base64'; let buffer = this.encode(key, msg); return !!buffer ? buffer.toString(code) : buffer; }
const onmessage = (event) => { if (this.showPackageLog && event.data.byteLength != 4) { this.logger.log('recv orgdata', event.data.byteLength, Buffer.from(event.data).toString('hex'));
let length = codec.decodeUInt32(this.getBytes()); let str = this.buffer.toString('utf8', this.offset, this.offset + length); this.offset += length;
response.on('end', function() { if (bufferLength) { body = Buffer.concat(buffers, bufferLength).toString('utf8'); } buffers = []; bufferLength = 0; if (response.statusCode >= 200 && response.statusCode <= 299) { try { var json_body = JSON.parse(body); self.emit('response', json_body); } catch (error) { // JSON.parse can throw only one exception, SyntaxError // All another exceptions throwing from user function, // because it just rethrowing for better error handling. if (error instanceof SyntaxError) { self.emit('error', error); } else { throw error; } } } else { var error = new ServerError(response.statusCode, body, 'Wrong response status code.'); self.emit('error', error); } });
file = fs.readFileSync(comd).toString(); } catch (e) { util.log(consts.COMANDS_EXEC_ERROR);
const pkg = JSON.parse(data.toString('utf-8', 1));
getCache():{dictVersion:string,protoVersion:string,dict:any,protos:any}{ try{ return JSON.parse(fs.readFileSync(__dirname+'/cache.tmp').toString())as any; }catch (err){ return null; } }
readString() { let len = this.readInt(); this.check(len); let r = this.buf.toString('utf8', this.pos, this.pos + len); this.pos += len; return r; }
const onmessage = (event) => { if (this.showPackageLog && event.data.byteLength != 4) { this.logger.log('recv orgdata', event.data.byteLength, Buffer.from(event.data).toString('hex'));
const pkg = JSON.parse(data.toString('utf-8', 1));