From f2807a1ec5afa664e5bf04d5cc57bcd4d49d24d2 Mon Sep 17 00:00:00 2001 From: Timofey Solomko Date: Sun, 8 Oct 2017 19:46:39 +0300 Subject: [PATCH] Start rework of Container API Add associated types, add info protocol, remove entryAttributes, add entry type property and enum. Docs comments were also removed so I won't forget update documentation before release. --- Sources/Common/Protocols.swift | 42 +++++++++++++++------------------- 1 file changed, 18 insertions(+), 24 deletions(-) diff --git a/Sources/Common/Protocols.swift b/Sources/Common/Protocols.swift index 7561e115..4488b587 100644 --- a/Sources/Common/Protocols.swift +++ b/Sources/Common/Protocols.swift @@ -24,47 +24,41 @@ public protocol DecompressionAlgorithm { /// A type that provides an implementation of a particular compression algorithm. public protocol CompressionAlgorithm { - /// Cmpress data with particular algorithm. + /// Compress data with particular algorithm. static func compress(data: Data) throws -> Data } -/// A type that represents a container of files, directories and/or other data. public protocol Container { - /// Retrieve all the entries from the container. - static func open(container: Data) throws -> [ContainerEntry] + associatedtype Entry: ContainerEntry + + static func open(container: Data) throws -> [Entry] + + static func info(container: Data) throws -> [Entry.Info] } -/// A type that represents an entry from a container (file or directory) with attributes. public protocol ContainerEntry { - /// Retrieve name of the entry from the container. - var name: String { get } + associatedtype Info: ContainerEntryInfo - /// Retrieve size of the entry's data from the container. - var size: Int { get } + var info: Info { get } - /// True, if entry is a directory. - var isDirectory: Bool { get } + var data: Data? { get } - /// True, if entry is a symbolic link. - var isLink: Bool { get } +} - /// Path to a linked file for symbolic link entry. - var linkPath: String? { get } +public protocol ContainerEntryInfo { - /** - Provides a dictionary with various attributes of the entry. - `FileAttributeKey` values are used as dictionary keys. + var name: String { get } - - Note: - Will be renamed to `attributes` in 4.0. - */ - var entryAttributes: [FileAttributeKey: Any] { get } + var size: Int { get } - /// Retrieve entry's data from the container. - func data() throws -> Data + var type: ContainerEntryType { get } + +} + +public enum ContainerEntryType { }