Repository navigation
4.0.0
Reworked "Container" API
There is a couple of ideas behind this rework:
- Enforce in API the idea that one can get information about entries without acquiring their data, but not vice versa.
- Provide a unified set of API for all three formats: ZIP, TAR and 7-Zip.
- Try to fix mistakes that were made in the development of previous versions.
Implementation of these ideas led to a lot of changes and here I will try to highlight most of them.
- New protocol:
ContainerEntryInfo.- It contains some informational properties from the previous version of
ContainerEntry. - There are also new properties such as
access/creation/modificationTimeandtype.
- It contains some informational properties from the previous version of
Comment: I would like to encourage you to check out this protocol's documentation as well as types that implement it: SevenZipEntryInfo, TarEntryInfo and ZipEntryInfo.
These types not only have protocol's properties, but also contain their own format-specific members which may be useful in certain cases.
ContainerEntrynow has only two members:infoanddataproperties.
Comment: All properties that existed in previous versions were either removed or moved to ContainerEntryInfo. One may also note that entry's data is now acquired through constant property rather than function. This means that it is no longer possible to asynchronously unpack ZIP containers, but it worth mentioning, that it was never intended in the first place.
ContainerEntrynow has an associated typeInfo: ContainerEntryInfo.ContainerEntry.entryAttributesremoved without replacement.
Comment: One may note that it is not a SWCompression's job to prepare entry's properties for the file system. Besides that, its existence was causing duplication of entry's information, so, in the end, it is for the best for this property to go.
Containernow has an associated typeEntry: ContainerEntry.openfunction now returns an array of associated typeEntry.- Added new function
infowhich returns an array ofEntry.Info.
Comment: One of the useful consequences of these changes is that it is no longer necessary to cast the result of open(container:) to specific entry type (such as ZipEntry).
- All existing ZIP, TAR and 7-Zip types conform to these protocols.
- Added missing types for ZIP, TAR and 7-Zip with conformances to these protocols.
ZipEntry,TarEntryandSevenZipEntrynow have only two members:infoanddata(in accordance withContainerEntryprotocol).- Standardised behaviour when
ContainerEntry.datacan benil:- If entry is a directory.
- If data is unavailable, but error wasn't thrown for some reason.
- 7-Zip only: if entry is an anti-file.
- Removed
SevenZipEntryInfo.isDirectory. Usetypeproperty instead. SevenZipEntryInfo.nameis no longerOptional.- Now throws
SevenZipError.internalStructureErrorwhen file names cannot be properly processed. - Entries now have empty strings as names when no names were found in container.
- Now throws
Common Types
Added several new common types which are used across the framework:
CompressionMethod.- Used as a type of
compressionMethodproperty ofGzipHeader,ZlibHeaderandZipEntryInfo. - Removed
GzipHeader.CompressionMethod.
- Used as a type of
ContainerEntryType.- Used as a type of
typeproperty ofContainerEntryInfo. - Removed
TarEntry.EntryType.
- Used as a type of
DosAttributes.- It is the same as
SevenZipEntryInfo.DosAttributestype from previous version. - Used as a type of
dosAttributesproperty ofSevenZipEntryInfoandZipEntryInfo.
- It is the same as
Permissions.- It is the same as
SevenZipEntryInfo.Permissionstype from previous version. - Used as a type of
permissionsproperty ofContainerEntryInfo.
- It is the same as
FileSystemType.- Used as a type of
GzipHeader.osTypeandZipEntryInfo.fileSystemTypeproperties. - Removed
GzipHeader.FileSystemType.
- Used as a type of
Errors
- Removed following errors:
SevenZipError.dataIsUnavailableLZMAError.decoderIsNotInitialisedLZMA2Error.wrongProperties(LZMA2Error.wrongDictionarySizeis thrown instead).TarError.wrongUstarVersion.TarError.notAsciiString(TarError.wrongFieldis thrown instead).XZError.wrongFieldValue(XZError.wrongFieldis thrown instead).
- Renamed following errors:
BZip2Error.wrongHuffmanLengthCodetoBZip2Error.wrongHuffmanCodeLength.BZip2Error.wrongCompressionMethodtoBZip2Error.wrongVersion.TarError.fieldIsNotNumbertoTarError.wrongField.XZError.reservedFieldValuetoXZError.wrongField.
- Standardised behaviour for errors with names similar to
wrongCRC:- These errors mean that everything went well, except for comparing the checksum.
- Their associated values now contain all "successfully" unpacked data, including the one which caused checksum error.
- This change affects
BZip2.decompress,GzipArchive.multiUnarchive,XZArchive.unarchive,XZArchive.splitUnarchive,ZipContainer.open.
- This change affects
- Some of these errors now have arrays as associated values to account for the situations with unpacked data being split.
- This change affects
GzipArchive.multiUnarchive,XZArchive.unarchive,XZArchive.splitUnarchive,ZipContainer.open.
- This change affects
General changes
- Renamed
XZArchive.multiUnarchivetoXZArchive.splitUnarchive. XZArchive.unarchivenow processes all XZ streams similar tosplitUnarchive, but combines them into one outputData.
Comment: These two changes are made to fix intended but apparently incorrect behaviour from previous versions, which was causing inconveniences with some archives.
- Fixed "bitReader is not aligned" precondition crash in Zlib.
- Fixed potential incorrect behavior when opening ZIP containers with size bigger than 4 GB.
- Updated to use Swift 4.
- Various improvements to documentation.
- "swcomp" is now included as part of this repository.
Comment: This was done to make it easier to synchronise changes between SWCompression and swcomp, if necessary. "swcomp" is not built by default.