|
7 | 7 |
|
8 | 8 | import Foundation |
9 | 9 | import Files |
10 | | -import CryptoSwift |
| 10 | +import Crypto |
11 | 11 |
|
12 | 12 | /// Represents a Git LFS pointer for a file. |
13 | 13 | /// |
@@ -68,11 +68,25 @@ public struct LFSPointer: Codable, Equatable, Hashable { |
68 | 68 | let file = try File(path: path.path) |
69 | 69 |
|
70 | 70 | self.version = "https://git-lfs.github.com/spec/v1" |
71 | | - |
72 | | - self.oid = try FileHandle(forReadingFrom: file.url).availableData.sha256().toHexString() |
| 71 | + |
| 72 | + let handle = try FileHandle(forReadingFrom: file.url) |
| 73 | + |
| 74 | + let readSize = 8192 |
| 75 | + var hasher = SHA256() |
| 76 | + |
| 77 | + while true { |
| 78 | + let data = handle.readData(ofLength: readSize) |
| 79 | + if data.count == 0 { |
| 80 | + break |
| 81 | + } |
| 82 | + |
| 83 | + hasher.update(data: data) |
| 84 | + } |
| 85 | + |
| 86 | + self.oid = String(hexEncoding: Data(hasher.finalize())) |
73 | 87 |
|
74 | 88 | let attr = try FileManager.default.attributesOfItem(atPath: file.path) |
75 | | - |
| 89 | + |
76 | 90 | self.size = (attr[.size] as? Int) ?? 0 |
77 | 91 |
|
78 | 92 | self.filename = file.name |
@@ -259,28 +273,6 @@ extension LFSPointer: CustomDebugStringConvertible { |
259 | 273 | } |
260 | 274 | } |
261 | 275 |
|
262 | | -public struct JSONPointer: Codable { |
263 | | - public let filename: String |
264 | | - public let filePath: String |
265 | | - public let pointer: LFSPointer |
266 | | -} |
267 | | - |
268 | | -/// Generates a string containing `JSON`. |
269 | | -/// - Parameter array: No description. |
270 | | -/// - Returns: A `String` containing `JSON`. |
271 | | -public func toJSON(array: [JSONPointer], jsonFormat: JSONEncoder.OutputFormatting = .init()) -> String { |
272 | | - |
273 | | - let encoder = JSONEncoder() |
274 | | - |
275 | | - encoder.outputFormatting = jsonFormat |
276 | | - |
277 | | - let jsonBytes = (try? encoder.encode(array)) ?? Data() |
278 | | - |
279 | | - let jsonString = String(data: jsonBytes, encoding: .utf8) ?? "" |
280 | | - |
281 | | - return jsonString |
282 | | -} |
283 | | - |
284 | 276 | public extension Array where Self.Element == LFSPointer { |
285 | 277 | /// Converts and `Array` of `LFSPointer`s to `JSON`. |
286 | 278 | /// - Parameter jsonFormat: The format of the generated `JSON`. |
|
0 commit comments