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)) } /**