Skip to content

4.0.0

Choose a tag to compare

@tsolomko tsolomko released this 18 Nov 10:36
· 1172 commits to develop since this release
v4.0.0
36f068e

Reworked "Container" API

There is a couple of ideas behind this rework:

  1. Enforce in API the idea that one can get information about entries without acquiring their data, but not vice versa.
  2. Provide a unified set of API for all three formats: ZIP, TAR and 7-Zip.
  3. 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/modificationTime and type.

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.

  • ContainerEntry now has only two members: info and data properties.

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.

  • ContainerEntry now has an associated type Info: ContainerEntryInfo.
  • ContainerEntry.entryAttributes removed 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.

  • Container now has an associated type Entry: ContainerEntry.
  • open function now returns an array of associated type Entry.
  • Added new function info which returns an array of Entry.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, TarEntry and SevenZipEntry now have only two members: info and data (in accordance with ContainerEntry protocol).
  • Standardised behaviour when ContainerEntry.data can be nil:
    • 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. Use type property instead.
  • SevenZipEntryInfo.name is no longer Optional.
    • Now throws SevenZipError.internalStructureError when file names cannot be properly processed.
    • Entries now have empty strings as names when no names were found in container.

Common Types

Added several new common types which are used across the framework:

  • CompressionMethod.
    • Used as a type of compressionMethod property of GzipHeader, ZlibHeader and ZipEntryInfo.
    • Removed GzipHeader.CompressionMethod.
  • ContainerEntryType.
    • Used as a type of type property of ContainerEntryInfo.
    • Removed TarEntry.EntryType.
  • DosAttributes.
    • It is the same as SevenZipEntryInfo.DosAttributes type from previous version.
    • Used as a type of dosAttributes property of SevenZipEntryInfo and ZipEntryInfo.
  • Permissions.
    • It is the same as SevenZipEntryInfo.Permissions type from previous version.
    • Used as a type of permissions property of ContainerEntryInfo.
  • FileSystemType.
    • Used as a type of GzipHeader.osType and ZipEntryInfo.fileSystemType properties.
    • Removed GzipHeader.FileSystemType.

Errors

  • Removed following errors:
    • SevenZipError.dataIsUnavailable
    • LZMAError.decoderIsNotInitialised
    • LZMA2Error.wrongProperties (LZMA2Error.wrongDictionarySize is thrown instead).
    • TarError.wrongUstarVersion.
    • TarError.notAsciiString (TarError.wrongField is thrown instead).
    • XZError.wrongFieldValue (XZError.wrongField is thrown instead).
  • Renamed following errors:
    • BZip2Error.wrongHuffmanLengthCode to BZip2Error.wrongHuffmanCodeLength.
    • BZip2Error.wrongCompressionMethod to BZip2Error.wrongVersion.
    • TarError.fieldIsNotNumber to TarError.wrongField.
    • XZError.reservedFieldValue to XZError.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.
    • 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.

General changes

  • Renamed XZArchive.multiUnarchive to XZArchive.splitUnarchive.
  • XZArchive.unarchive now processes all XZ streams similar to splitUnarchive, but combines them into one output Data.

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.