TAR
-
A type that allows to iteratively read TAR entries from a container provided by a
FileHandle
.The
TarReader
may be helpful in reducing the peak memory usage on certain platforms. However, to achieve this either theTarReader.process(_:)
function should be used or both the call toTarReader.read()
and the processing of the returned entry should be wrapped inside theautoreleasepool
. Since theautoreleasepool
is available only on Darwin platforms, the memory reducing effect may be not as significant on non-Darwin platforms (such as Linux or Windows).The following code demonstrates an example usage of the
TarReader
:let handle: FileHandle = ... let reader = TarReader(fileHandle: handle) try reader.process { ... } ... try handle.close()
Note that closing the
FileHandle
remains the responsibility of the caller.Important
Due to the API availability limitations of Foundation’sFileHandle
, on certain platforms errors inFileHandle
operations may result in unrecoverable runtime failures due to unhandled Objective-C exceptions (which are impossible to correctly handle in Swift code). As such, it is not recommended to useTarReader
on those platforms. The following platforms are unaffected by this issue: macOS 10.15.4+, iOS 13.4+, watchOS 6.2+, tvOS 13.4+, and any other platforms without Objective-C runtime.Declaration
Swift
public struct TarReader
-
A type that allows to iteratively create TAR containers with the output being written into a
FileHandle
.The
TarWriter
may be helpful in reducing the peak memory usage on certain platforms. However, to achieve this both the creation of TAR entries and the calls toTarWriter
should be wrapped inside theautoreleasepool
. Since theautoreleasepool
is available only on Darwin platforms, the memory reducing effect may be not as significant on non-Darwin platforms (such as Linux or Windows).The following code demonstrates an example usage of the
TarWriter
:let handle: FileHandle = ... let writer = TarWriter(fileHandle: handle) try autoreleasepool { let entry: TarEntry = ... try writer.append(entry) } try writer.finalize() try handle.close()
Note that
TarWriter.finalize()
must be called after finishing appending entries to the container. In addition, closing theFileHandle
remains the responsibility of the caller.Important
Due to the API availability limitations of Foundation’sFileHandle
, on certain platforms errors inFileHandle
operations may result in unrecoverable runtime failures due to unhandled Objective-C exceptions (which are impossible to correctly handle in Swift code). As such, it is not recommended to useTarWriter
on those platforms. The following platforms are unaffected by this issue: macOS 10.15.4+, iOS 13.4+, watchOS 6.2+, tvOS 13.4+, and any other platforms without Objective-C runtime.Declaration
Swift
public struct TarWriter
-
Represents an entry from the TAR container.
See moreDeclaration
Swift
public struct TarEntry : ContainerEntry
-
Provides access to information about an entry from the TAR container.
See moreDeclaration
Swift
public struct TarEntryInfo : ContainerEntryInfo