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.
This commit is contained in:
Timofey Solomko
2017-10-08 19:47:23 +03:00
parent 7ea25c38b1
commit f2807a1ec5
+18 -24
View File
@@ -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 {
}