下载文件中文乱码问题
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
parent
44519c5f8e
commit
d059d016a6
|
|
@ -61,7 +61,7 @@ function concatUint8(chunks, total) {
|
||||||
function createWriter(underlyingSource) {
|
function createWriter(underlyingSource) {
|
||||||
const files = Object.create(null)
|
const files = Object.create(null)
|
||||||
const filenames = []
|
const filenames = []
|
||||||
const encoder = new TextEncoder()
|
const encoder = new TextEncoder() // 保持UTF-8编码
|
||||||
|
|
||||||
let offset = 0 // bytes written to output so far
|
let offset = 0 // bytes written to output so far
|
||||||
let activeZipIndex = 0
|
let activeZipIndex = 0
|
||||||
|
|
@ -141,7 +141,7 @@ function createWriter(underlyingSource) {
|
||||||
if (fileLike.directory && !name.endsWith('/')) name += '/'
|
if (fileLike.directory && !name.endsWith('/')) name += '/'
|
||||||
if (files[name]) throw new Error('File already exists.')
|
if (files[name]) throw new Error('File already exists.')
|
||||||
|
|
||||||
const nameBuf = encoder.encode(name)
|
const nameBuf = encoder.encode(name) // 保持UTF-8编码
|
||||||
const commentBuf = encoder.encode(fileLike.comment || '')
|
const commentBuf = encoder.encode(fileLike.comment || '')
|
||||||
const { time, date } = dosDateTime(typeof fileLike.lastModified === 'undefined' ? Date.now() : fileLike.lastModified)
|
const { time, date } = dosDateTime(typeof fileLike.lastModified === 'undefined' ? Date.now() : fileLike.lastModified)
|
||||||
|
|
||||||
|
|
@ -174,15 +174,17 @@ function createWriter(underlyingSource) {
|
||||||
writeLocalHeader() {
|
writeLocalHeader() {
|
||||||
this.offset = offset
|
this.offset = offset
|
||||||
|
|
||||||
const generalPurposeBitFlag = 0x0008 // data descriptor present
|
// 关键修改:设置通用位标记,第11位(0x0800)表示文件名使用UTF-8编码
|
||||||
|
// 保留原0x0008(数据描述符存在),新增0x0800(UTF-8编码)
|
||||||
|
const generalPurposeBitFlag = 0x0808
|
||||||
const compressionMethod = 0 // store
|
const compressionMethod = 0 // store
|
||||||
const versionNeeded = 20 // 2.0 (ZIP64 switches this to 45)
|
const versionNeeded = this.needsZip64() ? 45 : 20 // 适配ZIP64
|
||||||
|
|
||||||
// We always use data descriptor; write zeros for crc/sizes in local header
|
// We always use data descriptor; write zeros for crc/sizes in local header
|
||||||
const local = getDataHelper(30 + this.nameBuf.length)
|
const local = getDataHelper(30 + this.nameBuf.length)
|
||||||
u32(local.view, 0, ZIP_SIGNATURE_LOCAL)
|
u32(local.view, 0, ZIP_SIGNATURE_LOCAL)
|
||||||
u16(local.view, 4, versionNeeded)
|
u16(local.view, 4, versionNeeded)
|
||||||
u16(local.view, 6, generalPurposeBitFlag)
|
u16(local.view, 6, generalPurposeBitFlag) // 应用UTF-8标记
|
||||||
u16(local.view, 8, compressionMethod)
|
u16(local.view, 8, compressionMethod)
|
||||||
u16(local.view, 10, this.time)
|
u16(local.view, 10, this.time)
|
||||||
u16(local.view, 12, this.date)
|
u16(local.view, 12, this.date)
|
||||||
|
|
@ -250,7 +252,8 @@ function createWriter(underlyingSource) {
|
||||||
|
|
||||||
const versionMadeBy = useZip64 ? 45 : 20
|
const versionMadeBy = useZip64 ? 45 : 20
|
||||||
const versionNeeded = useZip64 ? 45 : 20
|
const versionNeeded = useZip64 ? 45 : 20
|
||||||
const generalPurposeBitFlag = 0x0008
|
// 关键修改:中央目录也需要设置UTF-8标记
|
||||||
|
const generalPurposeBitFlag = 0x0808
|
||||||
const compressionMethod = 0
|
const compressionMethod = 0
|
||||||
|
|
||||||
const crc = file.crc ? file.crc.get() >>> 0 : 0
|
const crc = file.crc ? file.crc.get() >>> 0 : 0
|
||||||
|
|
@ -277,7 +280,7 @@ function createWriter(underlyingSource) {
|
||||||
u32(cd.view, 0, ZIP_SIGNATURE_CENTRAL)
|
u32(cd.view, 0, ZIP_SIGNATURE_CENTRAL)
|
||||||
u16(cd.view, 4, versionMadeBy)
|
u16(cd.view, 4, versionMadeBy)
|
||||||
u16(cd.view, 6, versionNeeded)
|
u16(cd.view, 6, versionNeeded)
|
||||||
u16(cd.view, 8, generalPurposeBitFlag)
|
u16(cd.view, 8, generalPurposeBitFlag) // 中央目录应用UTF-8标记
|
||||||
u16(cd.view, 10, compressionMethod)
|
u16(cd.view, 10, compressionMethod)
|
||||||
u16(cd.view, 12, file.time)
|
u16(cd.view, 12, file.time)
|
||||||
u16(cd.view, 14, file.date)
|
u16(cd.view, 14, file.date)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue