Skip to content

Commit

Permalink
clean
Browse files Browse the repository at this point in the history
  • Loading branch information
SusanDoggie committed Feb 26, 2022
1 parent 378b122 commit ed29e3c
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 26 deletions.
8 changes: 4 additions & 4 deletions Sources/DoggieCore/ApplePlatform/AppleCompression.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ extension AppleCompression {

private static let empty = [UInt8](repeating: 0, count: 4096)

private func _process(_ flag: Int32, _ callback: (UnsafeBufferPointer<UInt8>) -> Void) throws {
private func _process(_ flag: Int32, _ callback: (UnsafeBufferPointer<UInt8>) throws -> Void) throws {

var buffer = [UInt8](repeating: 0, count: 4096)

Expand All @@ -78,13 +78,13 @@ extension AppleCompression {

guard status == COMPRESSION_STATUS_OK || status == COMPRESSION_STATUS_END else { throw Error() }

callback(UnsafeBufferPointer(rebasing: buf.prefix(4096 - stream.dst_size)))
try callback(UnsafeBufferPointer(rebasing: buf.prefix(4096 - stream.dst_size)))

} while stream.src_size != 0 || stream.dst_size == 0
}
}

public func update(_ source: UnsafeBufferPointer<UInt8>, _ callback: (UnsafeBufferPointer<UInt8>) -> Void) throws {
public func update(_ source: UnsafeBufferPointer<UInt8>, _ callback: (UnsafeBufferPointer<UInt8>) throws -> Void) throws {

guard let _source = source.baseAddress, source.count != 0 else { return }

Expand All @@ -94,7 +94,7 @@ extension AppleCompression {
try _process(0, callback)
}

public func finalize(_ callback: (UnsafeBufferPointer<UInt8>) -> Void) throws {
public func finalize(_ callback: (UnsafeBufferPointer<UInt8>) throws -> Void) throws {

try AppleCompression.empty.withUnsafeBufferPointer { empty in

Expand Down
6 changes: 3 additions & 3 deletions Sources/DoggieCore/Compression/CompressionCodec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,17 @@

public protocol CompressionCodec: AnyObject {

func update(_ source: UnsafeBufferPointer<UInt8>, _ callback: (UnsafeBufferPointer<UInt8>) -> Void) throws
func update(_ source: UnsafeBufferPointer<UInt8>, _ callback: (UnsafeBufferPointer<UInt8>) throws -> Void) throws

func finalize(_ callback: (UnsafeBufferPointer<UInt8>) -> Void) throws
func finalize(_ callback: (UnsafeBufferPointer<UInt8>) throws -> Void) throws

func process<C: RangeReplaceableCollection>(_ source: Data, _ output: inout C) throws where C.Element == UInt8
}

extension CompressionCodec {

@inlinable
public func update<S: DataProtocol>(_ source: S, _ callback: (UnsafeBufferPointer<UInt8>) -> Void) throws {
public func update<S: DataProtocol>(_ source: S, _ callback: (UnsafeBufferPointer<UInt8>) throws -> Void) throws {
try source.regions.forEach { try $0.withUnsafeBytes { try update($0.bindMemory(to: UInt8.self), callback) } }
}

Expand Down
6 changes: 3 additions & 3 deletions Sources/DoggieCore/Compression/brotli/BrotliDecoder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ extension BrotliDecoder {

extension BrotliDecoder {

public func update(_ source: UnsafeBufferPointer<UInt8>, _ callback: (UnsafeBufferPointer<UInt8>) -> Void) throws {
public func update(_ source: UnsafeBufferPointer<UInt8>, _ callback: (UnsafeBufferPointer<UInt8>) throws -> Void) throws {

var buffer = [UInt8](repeating: 0, count: 4096)

Expand All @@ -71,13 +71,13 @@ extension BrotliDecoder {

guard status != BROTLI_DECODER_RESULT_ERROR else { throw Error(code: BrotliDecoderGetErrorCode(stream)) }

callback(UnsafeBufferPointer(rebasing: buf.prefix(4096 - avail_out)))
try callback(UnsafeBufferPointer(rebasing: buf.prefix(4096 - avail_out)))

} while avail_in != 0 || BrotliDecoderHasMoreOutput(stream) == BROTLI_TRUE
}
}

public func finalize(_ callback: (UnsafeBufferPointer<UInt8>) -> Void) throws {
public func finalize(_ callback: (UnsafeBufferPointer<UInt8>) throws -> Void) throws {
try update(UnsafeBufferPointer(start: nil, count: 0), callback)
}
}
8 changes: 4 additions & 4 deletions Sources/DoggieCore/Compression/brotli/BrotliEncoder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ extension BrotliEncoder {

extension BrotliEncoder {

private func _process(_ op: BrotliEncoderOperation, _ source: UnsafeBufferPointer<UInt8>, _ callback: (UnsafeBufferPointer<UInt8>) -> Void) throws {
private func _process(_ op: BrotliEncoderOperation, _ source: UnsafeBufferPointer<UInt8>, _ callback: (UnsafeBufferPointer<UInt8>) throws -> Void) throws {

var buffer = [UInt8](repeating: 0, count: 4096)

Expand All @@ -79,17 +79,17 @@ extension BrotliEncoder {

guard status == BROTLI_TRUE else { throw Error.unknown }

callback(UnsafeBufferPointer(rebasing: buf.prefix(4096 - avail_out)))
try callback(UnsafeBufferPointer(rebasing: buf.prefix(4096 - avail_out)))

} while avail_in != 0 || BrotliEncoderHasMoreOutput(stream.ptr) == BROTLI_TRUE
}
}

public func update(_ source: UnsafeBufferPointer<UInt8>, _ callback: (UnsafeBufferPointer<UInt8>) -> Void) throws {
public func update(_ source: UnsafeBufferPointer<UInt8>, _ callback: (UnsafeBufferPointer<UInt8>) throws -> Void) throws {
try _process(BROTLI_OPERATION_PROCESS, source, callback)
}

public func finalize(_ callback: (UnsafeBufferPointer<UInt8>) -> Void) throws {
public func finalize(_ callback: (UnsafeBufferPointer<UInt8>) throws -> Void) throws {
try _process(BROTLI_OPERATION_FINISH, UnsafeBufferPointer(start: nil, count: 0), callback)
}
}
Expand Down
8 changes: 4 additions & 4 deletions Sources/DoggieCore/Compression/zlib/zlib.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ extension _Z_STREAM {

extension _Z_STREAM {

private func _process(_ flag: Int32, _ callback: (UnsafeBufferPointer<UInt8>) -> Void) throws {
private func _process(_ flag: Int32, _ callback: (UnsafeBufferPointer<UInt8>) throws -> Void) throws {

var buffer = [UInt8](repeating: 0, count: 4096)

Expand All @@ -80,13 +80,13 @@ extension _Z_STREAM {

guard status == Z_OK || status == Z_BUF_ERROR || status == Z_STREAM_END else { throw Error(code: status, msg: stream.msg) }

callback(UnsafeBufferPointer(rebasing: buf.prefix(4096 - Int(stream.avail_out))))
try callback(UnsafeBufferPointer(rebasing: buf.prefix(4096 - Int(stream.avail_out))))

} while stream.avail_in != 0 || stream.avail_out == 0
}
}

public func update(_ source: UnsafeBufferPointer<UInt8>, _ callback: (UnsafeBufferPointer<UInt8>) -> Void) throws {
public func update(_ source: UnsafeBufferPointer<UInt8>, _ callback: (UnsafeBufferPointer<UInt8>) throws -> Void) throws {

guard let _source = source.baseAddress, source.count != 0 else { return }

Expand All @@ -96,7 +96,7 @@ extension _Z_STREAM {
try _process(Z_NO_FLUSH, callback)
}

public func finalize(_ callback: (UnsafeBufferPointer<UInt8>) -> Void) throws {
public func finalize(_ callback: (UnsafeBufferPointer<UInt8>) throws -> Void) throws {

stream.next_in = nil
stream.avail_in = 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public class TIFFLZWEncoder: CompressionCodec {
self.table.reserveCapacity(tableLimit - 258)
}

public func update(_ source: UnsafeBufferPointer<UInt8>, _ callback: (UnsafeBufferPointer<UInt8>) -> Void) throws {
public func update(_ source: UnsafeBufferPointer<UInt8>, _ callback: (UnsafeBufferPointer<UInt8>) throws -> Void) throws {

guard !isEndOfStream else { throw Error.endOfStream }

Expand Down Expand Up @@ -126,21 +126,21 @@ public class TIFFLZWEncoder: CompressionCodec {
}

if writer.buffer.count > 4095 {
writer.buffer.withUnsafeBufferPointer(callback)
try writer.buffer.withUnsafeBufferPointer(callback)
writer.buffer.removeAll(keepingCapacity: true)
}
}
}

public func finalize(_ callback: (UnsafeBufferPointer<UInt8>) -> Void) throws {
public func finalize(_ callback: (UnsafeBufferPointer<UInt8>) throws -> Void) throws {

guard !isEndOfStream else { throw Error.endOfStream }

writer.write(257, log2(UInt(table.count + 258)) + 1)

writer.finalize()

writer.buffer.withUnsafeBufferPointer(callback)
try writer.buffer.withUnsafeBufferPointer(callback)

isEndOfStream = true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class TIFFPackBitsEncoder: CompressionCodec {
self.repeat_count = 0
}

public func update(_ source: UnsafeBufferPointer<UInt8>, _ callback: (UnsafeBufferPointer<UInt8>) -> Void) throws {
public func update(_ source: UnsafeBufferPointer<UInt8>, _ callback: (UnsafeBufferPointer<UInt8>) throws -> Void) throws {

guard !isEndOfStream else { throw Error.endOfStream }

Expand Down Expand Up @@ -88,13 +88,13 @@ public class TIFFPackBitsEncoder: CompressionCodec {
}

if buffer.count > 4095 {
buffer.withUnsafeBufferPointer(callback)
try buffer.withUnsafeBufferPointer(callback)
buffer.removeAll(keepingCapacity: true)
}
}
}

public func finalize(_ callback: (UnsafeBufferPointer<UInt8>) -> Void) throws {
public func finalize(_ callback: (UnsafeBufferPointer<UInt8>) throws -> Void) throws {

guard !isEndOfStream else { throw Error.endOfStream }

Expand All @@ -111,7 +111,7 @@ public class TIFFPackBitsEncoder: CompressionCodec {

buffer.append(128)

buffer.withUnsafeBufferPointer(callback)
try buffer.withUnsafeBufferPointer(callback)

isEndOfStream = true
}
Expand Down

0 comments on commit ed29e3c

Please sign in to comment.