Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

如何读取.rar多个文件? #17

Open
LostRainbowSea opened this issue Jan 18, 2022 · 3 comments
Open

如何读取.rar多个文件? #17

LostRainbowSea opened this issue Jan 18, 2022 · 3 comments

Comments

@LostRainbowSea
Copy link

switch (type) {
case 0x74:
const entry = yield this.parseEntry(size, offset);
this.entries.push(entry);
//offset += entry.blockSize;使用这个只能读取一个文件
offset += size;
break;
default:
offset += size;
}

@LostRainbowSea
Copy link
Author

可惜的是,压缩包内文件名并不支持中文,否则会报错

@LostRainbowSea
Copy link
Author

如何支持RAR5.0呢?

@278333422
Copy link

可惜的是,压缩包内文件名并不支持中文,否则会报错

function getString(view, length, offset, raw) {
    offset = offset || 0;
    length = length || (view.byteLength - offset);
    if (length < 0) {
        length += view.byteLength;
    }
    let str = '';
    if (typeof Buffer !== 'undefined') {
        const data = [];
        for (let i = offset; i < (offset + length); i++) {
            data.push(view.getUint8(i));
        }
       return (new Buffer(data)).toString();
    }
    else {
        const data = [];
    	for (let i = offset; i < (offset + length); i++) {
    	     str += String.fromCharCode(view.getUint8(i));
    	     data.push(view.getUint8(i));
         }
        if (raw) {
            return str;
        }
    // TODO: why does this work?
	var gbkDecoder=new TextDecoder('gbk');
	return (gbkDecoder.decode(new Uint8Array(data)));
    //return decodeURIComponent(window.escape(str));
    }
}

看else以后的 gbk我是这么改的
还有一行也改了下
entry.path = entry.path.split('\x00')[1];
改为
entry.path = entry.path.split('\x00')[0];

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants