in Sources/TSFCASFileTree/FileTreeImport.swift [771:815]
func describeAllSegments(of file: FileSegmenter, _ ctx: Context) throws -> [SegmentDescriptor] {
var descriptions: [SegmentDescriptor] = []
for segmentNumber in (0...Int.max) {
let (data, isEOF): (LLBFastData, Bool)
do {
guard let value = try file.fetchSegment(segmentNumber: segmentNumber) else {
// File EOF'ed prematurely.
if self.options.relaxConsistencyChecks {
return descriptions
} else {
throw FileSegmenter.Error.resourceChanged(reason: "Can't read")
}
}
(data, isEOF) = value
} catch FileSegmenter.Error.resourceChanged(let reason) {
// Translate this resource consistency error,
// will throw all the rest as is.
throw ImportError.modifiedFile(file.path, reason: reason)
}
var useCompression: Bool
if case .compressed = options.wireFormat, file.size > 1024, !file.path.looksLikeCompressed, options.compressBufferAllocator != nil {
useCompression = true
} else {
useCompression = false
}
let segment: AnnotatedSegment
if useCompression, let compressedSegment = try? data.compressed(allocator: options.compressBufferAllocator!) {
segment = AnnotatedSegment(isCompressed: true, uncompressedSize: data.count, data: compressedSegment)
} else {
useCompression = false
segment = AnnotatedSegment(isCompressed: false, uncompressedSize: data.count, data: data)
}
descriptions.append(.init(of: segment, id: _db.identify(refs: [], data: segment.data.toByteBuffer(), ctx)))
if isEOF {
break
}
}
assert(descriptions.reduce(0, { acc, d in acc + d.uncompressedSize }) == file.size)
return descriptions
}