From 2597ab4ea1eb4d70c33bfa65447d44d7478182d3 Mon Sep 17 00:00:00 2001 From: lyswhut Date: Sun, 23 Jul 2023 19:57:36 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=9F=90=E4=BA=9Btx=E6=BA=90?= =?UTF-8?q?=E6=AD=8C=E8=AF=8D=E5=9B=A0=E6=95=B0=E6=8D=AE=E5=BC=82=E5=B8=B8?= =?UTF-8?q?=E8=A7=A3=E6=9E=90=E5=A4=B1=E8=B4=A5=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- publish/changeLog.md | 1 + .../winMain/rendererEvent/tx_decodeLyric.ts | 28 ++++++++++++++----- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/publish/changeLog.md b/publish/changeLog.md index f502a07f..d90b0859 100644 --- a/publish/changeLog.md +++ b/publish/changeLog.md @@ -12,6 +12,7 @@ - 修复我的列表名右键菜单-排序歌曲按专辑名排序无效的问题(#1440) - 修复若路径存在 # 字符时,软件无法启动的问题 - 修复搜索框在某些情况下输入内容后搜索时会自动清空的问题(#1472) +- 修复某些tx源歌词因数据异常解析失败的问题 ### 其他 diff --git a/src/main/modules/winMain/rendererEvent/tx_decodeLyric.ts b/src/main/modules/winMain/rendererEvent/tx_decodeLyric.ts index 34905518..af56ebc9 100644 --- a/src/main/modules/winMain/rendererEvent/tx_decodeLyric.ts +++ b/src/main/modules/winMain/rendererEvent/tx_decodeLyric.ts @@ -1,4 +1,4 @@ -import { inflate } from 'zlib' +import { createInflate, constants as zlibConstants } from 'node:zlib' // import path from 'path' import { mainHandle } from '@common/mainIpc' import { WIN_MAIN_RENDERER_EVENT_NAME } from '@common/ipcNames' @@ -8,15 +8,29 @@ import { WIN_MAIN_RENDERER_EVENT_NAME } from '@common/ipcNames' let qrc_decode: (buf: Buffer, len: number) => Buffer +const inflate = async(lrcBuf: Buffer) => new Promise((resolve, reject) => { + const buffer_builder: Buffer[] = [] + const decompress_stream = createInflate() + .on('data', (chunk) => { + buffer_builder.push(chunk) + }) + .on('close', () => { + resolve(Buffer.concat(buffer_builder).toString()) + }) + .on('error', (err: any) => { + // console.log(err) + if (err.errno !== zlibConstants.Z_BUF_ERROR) { // EOF: expected + reject(err) + } + }) + // decompress_stream.write(lrcBuf) + decompress_stream.end(lrcBuf) +}) + const decode = async(str: string): Promise => { if (!str) return '' const buf = Buffer.from(str, 'hex') - return new Promise((resolve, reject) => { - inflate(qrc_decode(buf, buf.length), (err, lrc) => { - if (err) reject(err) - else resolve(lrc.toString()) - }) - }) + return inflate(qrc_decode(buf, buf.length)) }