本文整理匯總了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(_);
}
};