Skip to content

Commit aada36d

Browse files
committed
Add documentation; tweak name of decoder()
1 parent 13551ac commit aada36d

1 file changed

Lines changed: 17 additions & 5 deletions

File tree

Sources/ATCommonTools/Swift-bound/ContentDecoder.swift

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,24 @@ import Foundation
1212
/// This allows pluggable decompression handlers (e.g. Gzip, Brotli, etc).
1313
public protocol ContentDecoderProtocol: Sendable {
1414

15-
///
15+
/// The name of the header.
1616
var encodingName: String { get }
1717

18-
/// Decode input data asynchronously.
18+
/// Decodes input data asynchronously.
19+
///
20+
/// - Parameter data: The data to decode.
21+
/// - Returns: The now-decoded `Data` object.
1922
func decode(_ data: Data) async throws -> Data
2023
}
2124

22-
///
25+
/// An enumeration which represents all decompression algorithms that the stream can use to decode
26+
/// the data.
2327
public enum ContentDecoders {
2428

2529
/// An array of content decoders.
30+
///
31+
/// This is meant to be fixed. Do not change the list of decoders unless the `common` TypeScript
32+
/// package in the `atproto` repository makes a change.
2633
private static let decoders: [String: ContentDecoderProtocol] = {
2734
let all: [ContentDecoderProtocol] = [
2835
// GzipDecoder(),
@@ -32,12 +39,17 @@ public enum ContentDecoders {
3239
return Dictionary(uniqueKeysWithValues: all.map { ($0.encodingName.lowercased(), $0) })
3340
}()
3441

42+
/// Normalizes encoding string.
3543
///
36-
public static func decoder(for encoding: String) -> ContentDecoderProtocol? {
44+
/// - Parameter encoding: The string to decode.
45+
/// - Returns: An object conforming to ``ContentDecoderProtocol`` if the normaliz
46+
public static func decode(for encoding: String) -> ContentDecoderProtocol? {
3747
decoders[encoding.lowercased()]
3848
}
3949

40-
///
50+
/// Compiles all of the keys from ``decoders`` into one array.
51+
///
52+
/// - Returns: An array of all of the keys from ``decoders`` as `String` objects.
4153
public static var allEncodingNames: [String] {
4254
Array(decoders.keys)
4355
}

0 commit comments

Comments
 (0)