当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript Buffer.concat方法代码示例

本文整理汇总了TypeScript中buffer.Buffer.concat方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Buffer.concat方法的具体用法?TypeScript Buffer.concat怎么用?TypeScript Buffer.concat使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在buffer.Buffer的用法示例。


在下文中一共展示了Buffer.concat方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: encodeString

function encodeString(s: string): Buffer {
    let bytes = Buffer.from(s);
    return Buffer.concat([
        Buffer.from(bytes.length.toString()),
        Buffer.from(':'),
        bytes]);
}
开发者ID:avli,项目名称:bencoder,代码行数:7,代码来源:bencoder.ts

示例2: encodeArray

function encodeArray(l: Array<any>): Buffer {
    let result: Array<Buffer> = [Buffer.from('l')];
    l.forEach(element => {
        result.push(_encode(element));
    });
    result.push(Buffer.from('e'))
    return Buffer.concat(result);
}
开发者ID:avli,项目名称:bencoder,代码行数:8,代码来源:bencoder.ts

示例3: hash

  /**
   * Computes a sha3-256 hash of the serialized tx, using the sender address to generate a fake
   * signature.
   *
   * @param includeSignature - Whether or not to include the signature
   */
  hash(includeSignature = true): Buffer {
    if (includeSignature && this._from && this._from.toString('hex') !== '') {
      // include a fake signature using the from address as a private key
      const fakeKey = Buffer.concat([this._from, this._from.slice(0, 12)])
      this.sign(fakeKey)
    }

    return super.hash(includeSignature)
  }
开发者ID:ethereumjs,项目名称:ethereumjs-tx,代码行数:15,代码来源:fake.ts

示例4: encode

export function encode({ opt, data }) {
  const bufList: Buffer[] = [];
  let byteLen = 0;
  let offset = 0;

  data = Array.isArray(data) ? data : [data];
  let buf = Buffer.alloc(allocLen);
  bufList.push(buf);

  const writeUInt = (value, byteLength) => {
    byteLen += byteLength;
    const less = allocLen - offset;
    if (less < byteLength) {
      if (less) {
        // split buffer
        byteLength -= less;
        const i = Math.pow(2, byteLength * 8);
        const l = (value / i) >>> 0;
        value -= l * i;
        buf.writeUIntBE(l, offset, less);
      }

      buf = Buffer.alloc(allocLen);
      bufList.push(buf);
      offset = 0;
    }

    buf.writeUIntBE(value, offset, byteLength);
    offset += byteLength;
  };

  writeUInt(opt, OPT_LEN);

  // set buffer
  data.forEach((item) => {
    const packetType = packetTypes[item.type];
    writeUInt(item.type, PACKET_TYPE_LEN);

    for (const key in packetType) {
      if (packetType.hasOwnProperty(key)) {
        let value = +item.packet[key] || 0;
        const packetItem = packetType[key];
        const byteLength = packetItem.byteLen;
        if (packetItem.encode) {
          value = packetItem.encode(value);
        }
        writeUInt(value, byteLength);
      }
    }
  });

  if (bufList.length > 1) {
    buf = Buffer.concat(bufList, bufList.length * allocLen);
  }

  return buf.buffer.slice(buf.byteOffset, buf.byteOffset + byteLen);
}
开发者ID:whxaxes,项目名称:slither,代码行数:57,代码来源:utils.ts

示例5: encodeDict

function encodeDict(d: any): Buffer {
    let result: Array<Buffer> = [Buffer.from('d')];
    let keys = Object.keys(d).sort();
    keys.forEach(k => {
        result.push(encodeString(k));
        result.push(encode(d[k]))
    });
    result.push(Buffer.from('e'));
    return Buffer.concat(result);
}
开发者ID:avli,项目名称:bencoder,代码行数:10,代码来源:bencoder.ts

示例6: resolve

        client.on('data', data => {
            nreplResp = Buffer.concat([nreplResp, data]);
            const { decodedObjects, rest } = bencodeUtil.decodeObjects(nreplResp);
            nreplResp = rest;
            const validDecodedObjects = decodedObjects.reduce((objs, obj) => {
                if (!isLastNreplObject(objs))
                    objs.push(obj);
                return objs;
            }, []);
            respObjects.push(...validDecodedObjects);

            if (isLastNreplObject(respObjects)) {
                client.end();
                client.removeAllListeners();
                resolve(respObjects);
            }
        });
开发者ID:avli,项目名称:clojureVSCode,代码行数:17,代码来源:nreplClient.ts

示例7:

			.on('end', () => {
				const buffer = Buffer.concat(chunks);
				res(buffer.toString('hex'));
			});
开发者ID:ha-dai,项目名称:Misskey,代码行数:4,代码来源:add-file.ts

示例8:

 res.on("data", (d) => {
     buffer = Buffer.concat([buffer, d]);
 });
开发者ID:Half-Shot,项目名称:matrix-appservice-discord,代码行数:3,代码来源:util.ts

示例9:

 }).on('end', () => {
     res.end('You posted me this: ' + Buffer.concat(body).toString());
 });
开发者ID:AbraaoAlves,项目名称:DefinitelyTyped,代码行数:3,代码来源:uws-tests.ts


注:本文中的buffer.Buffer.concat方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。