From acf4faad8e1325cadf0e2a8ac57eac27df6f0c26 Mon Sep 17 00:00:00 2001 From: Sloaix Date: Mon, 7 Aug 2023 12:26:11 +0800 Subject: [PATCH] chore: release 0.1.4 --- package.json | 2 +- src/encoder.ts | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 6f84615..7b61f25 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "sloaix-node-bencode", - "version": "0.1.3", + "version": "0.1.4", "description": "Bencode encoding and decoding, with both library and CLI versions available. The CLI version can decode bencode-formatted data from files or strings and output the result in JSON format.", "keywords": [ "bencode", diff --git a/src/encoder.ts b/src/encoder.ts index 7d23ff5..75983a9 100644 --- a/src/encoder.ts +++ b/src/encoder.ts @@ -56,7 +56,11 @@ export class Bencoder { // 字符串的编码格式为:字符串的长度 + ':' + 字符串 // 例如:4:spam - return this.encoder.encode(`${byteString.toString().length}:${byteString}`) + const buffers: Uint8Array[] = [this.encoder.encode(`${byteString.toString().length}:`)] + + buffers.push(Buffer.from(byteString)) + + return Uint8Array.from(Buffer.concat(buffers)) } /**