0001 // Data.swift 0002 // 0003 // The MIT License (MIT) 0004 // 0005 // Copyright (c) 2015 Zewo 0006 // 0007 // Permission is hereby granted, free of charge, to any person obtaining a copy 0008 // of this software and associated documentation files (the "Software"), to deal 0009 // in the Software without restriction, including without limitation the rights 0010 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 0011 // copies of the Software, and to permit persons to whom the Software is 0012 // furnished to do so, subject to the following conditions: 0013 // 0014 // The above copyright notice and this permission notice shall be included in all 0015 // copies or substantial portions of the Software. 0016 // 0017 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 0018 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 0019 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 0020 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 0021 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 0022 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 0023 // SOFTWARE. 0024 0025 public struct Data: ArrayLiteralConvertible, StringLiteralConvertible { 0026 0027 private enum Storage
Base64.swift:174 public static func encode(data: Data, charsPerLine: Int? = nil, specialChars: String? = nil) -> Data {Base64.swift:174 public static func encode(data: Data, charsPerLine: Int? = nil, specialChars: String? = nil) -> Data {Base64.swift:176 return Data(uBytes: encoder.output)Base64.swift:179 public static func decode(data: Data) -> Data {Base64.swift:179 public static func decode(data: Data) -> Data {Base64.swift:181 return Data(uBytes: decoder.output)File.swift:59 public func write(data: Data) throws {File.swift:64 public func read(length length: Int = Int.max) throws -> Data {File.swift:76 return Data(uBytes: bytes){ 0028 case Bytes
Data.swift:32 private var raw: Storage([Int8]) 0029 case Text
Data.swift:37 self.raw = .Bytes(bytes)Data.swift:41 self.raw = .Bytes(unsafeBitCast(uBytes, [Int8].self))Data.swift:72 case .Bytes(let bytes):Data.swift:83 case .Bytes(let bytes):Data.swift:92 case .Bytes(let bytes):Data.swift:101 case .Bytes(let bytes):(String) 0030 } 0031 0032 private var raw
Data.swift:45 self.raw = .Text(string)Data.swift:74 case .Text(let string):Data.swift:85 case .Text(let string):Data.swift:94 case .Text(let string):Data.swift:103 case .Text(let string):: Storage 0033 0034 // MARK: - Initializers 0035 0036 public init(bytes: [Int8]) { 0037 self.raw = .Bytes(bytes) 0038 } 0039 0040 public init
Data.swift:37 self.raw = .Bytes(bytes)Data.swift:41 self.raw = .Bytes(unsafeBitCast(uBytes, [Int8].self))Data.swift:45 self.raw = .Text(string)Data.swift:71 switch raw {Data.swift:82 switch raw {Data.swift:91 switch raw {Data.swift:100 switch raw {(uBytes: [UInt8]) { 0041 self.raw = .Bytes(unsafeBitCast(uBytes, [Int8].self)) 0042 } 0043 0044 public init
Base64.swift:176 return Data(uBytes: encoder.output)Base64.swift:181 return Data(uBytes: decoder.output)Data.swift:51 self.init(uBytes: elements)File.swift:76 return Data(uBytes: bytes)(string: String) { 0045 self.raw = .Text(string) 0046 } 0047 0048 // MARK: - ArrayLiteralConvertible 0049 0050 public init(arrayLiteral elements: UInt8...) { 0051 self.init(uBytes: elements) 0052 } 0053 0054 // MARK: - StringLiteralConvertible 0055 0056 public init(stringLiteral value: StringLiteralType) { 0057 self.init(string: value) 0058 } 0059 0060 public init(extendedGraphemeClusterLiteral value: String) { 0061 self.init(string: value) 0062 } 0063 0064 public init(unicodeScalarLiteral value: String) { 0065 self.init(string: value) 0066 } 0067 0068 // MARK: - Length 0069 0070 public var length
Data.swift:57 self.init(string: value)Data.swift:61 self.init(string: value)Data.swift:65 self.init(string: value): Int { 0071 switch raw { 0072 case .Bytes(let bytes): 0073 return bytes.count 0074 case .Text(let string): 0075 return string.nulTerminatedUTF8.count 0076 } 0077 } 0078 0079 // MARK: - Getters 0080 0081 public var bytes: [Int8] { 0082 switch raw { 0083 case .Bytes(let bytes): 0084 return bytes 0085 case .Text(let string): 0086 return unsafeBitCast(Array(string.nulTerminatedUTF8), [Int8].self) 0087 } 0088 } 0089 0090 public var uBytes
File.swift:60 let count = fwrite(data.uBytes, 1, data.length, fp)File.swift:61 guard count == data.length else { throw Error.WriteError(String.fromCString(strerror(ferror(fp))) ?? "") }: [UInt8] { 0091 switch raw { 0092 case .Bytes(let bytes): 0093 return unsafeBitCast(bytes, [UInt8].self) 0094 case .Text(let string): 0095 return Array(string.nulTerminatedUTF8) 0096 } 0097 } 0098 0099 public var string: String? { 0100 switch raw { 0101 case .Bytes(let bytes): 0102 return String(data: unsafeBitCast(bytes, [UInt8].self)) 0103 case .Text(let string): 0104 return string 0105 } 0106 } 0107 0108 } 0109
Base64.swift:175 let encoder = Base64Encoder(bytes: data.uBytes, charsPerLine: charsPerLine, specialChars: specialChars)Base64.swift:180 let decoder = Base64Decoder(bytes: data.uBytes)File.swift:60 let count = fwrite(data.uBytes, 1, data.length, fp)