本文整理汇总了TypeScript中streamline-runtime._.handshake方法的典型用法代码示例。如果您正苦于以下问题:TypeScript _.handshake方法的具体用法?TypeScript _.handshake怎么用?TypeScript _.handshake使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类streamline-runtime._
的用法示例。
在下文中一共展示了_.handshake方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: return
return (_: _, reader: Reader<Buffer>, writer: Writer<any>) => {
const binReader = binary.reader(reader);
const handshake = _.handshake();
while (true) {
var buf = binReader.readData(_, 2048);
if (!buf || !buf.length) return;
var str = buf.toString("binary");
var i = str.indexOf(boundary);
if (i < 0) throw new Error("boundary not found");
var lines = str.substring(0, i).split(/\r?\n/);
var headers = lines.slice(0, lines.length - 2).reduce((h: any, l: string) => {
const kv = l.split(/\s*:\s*/);
h[kv[0].toLowerCase()] = kv[1];
return h;
}, {});
i = str.indexOf('\n', i);
binReader.unread(buf.length - i - 1);
var read = (_: _) => {
const len = Math.max(boundary.length, 256);
const buf = binReader.readData(_, 32 * len);
if (!buf || !buf.length) {
handshake.notify();
return;
}
// would be nice if Buffer had an indexOf. Would avoid a conversion to string.
// I could use node-buffertools but it introduces a dependency on a binary module.
const s = buf.toString("binary");
const i = s.indexOf(boundary);
if (i === 0) {
const j = s.indexOf('\n', boundary.length);
if (j < 0) throw new Error("newline missing after boundary");
binReader.unread(buf.length - j - 1);
handshake.notify();
return undefined;
} else if (i > 0) {
var j = s.lastIndexOf('\n', i);
if (s[j - 1] === '\r') j--;
binReader.unread(buf.length - i);
return buf.slice(0, j);
} else {
binReader.unread(buf.length - 31 * len);
return buf.slice(0, 31 * len);
}
};
const partReader = generic.reader(read);
partReader.headers = headers;
writer.write(_, partReader);
handshake.wait(_);
}
};