简体   繁体   中英

Platform independent way to read ZIP archives with TrueZip

This may be an obvious question but I couldn't seem to find an answer.

We are using TrueZip 7.7.1 and creating instances of the ZipFile to read ZIP archives. When getting entries or input streams from the ZipFile we have to specify the entry name which may contain the path separator for the file system that it was created on. The current implementation is naive and uses the File.separator provided by the JVM but that doesn't work if the archive was created on a file system with a different separator.

It seems like there is some way to do this with TPath as that can apparently use either File.separator or "/" on either platform.

What's the best way to read ZIP archives in a platform independent manor with TrueZip 7.7.1?

According to the ZIP file format specifications ( link ), all paths should be stored with '/' (thus being platform independent):

4.4.17.1 The name of the file, with optional relative path. The path stored MUST not contain a drive or device letter, or a leading slash. All slashes MUST be forward slashes '/' as opposed to backwards slashes '\\' for compatibility with Amiga and UNIX file systems etc. If input came from standard input, there is no file name field.

So if you just stick to this convention, you should not have to worry about the platform you are running on at all.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM