Skip to content

Commit

Permalink
fix NIO 2.9.0 deprecations (#61)
Browse files Browse the repository at this point in the history
Motivation:

Usage of deprecated methods is bad.

Modification:

Fix usage of deprecated methods.

Result:

Fewer warnings.
  • Loading branch information
artemredkin authored and weissi committed Oct 24, 2019
1 parent 0584020 commit ed97628
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ let package = Package(
.library(name: "NIOHTTPCompression", targets: ["NIOHTTPCompression"]),
],
dependencies: [
.package(url: "https://github.com/apple/swift-nio.git", from: "2.2.0"),
.package(url: "https://github.com/apple/swift-nio.git", from: "2.9.0"),
],
targets: targets
)
9 changes: 4 additions & 5 deletions Sources/NIOHTTPCompression/HTTPDecompression.swift
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,6 @@ public enum NIOHTTPDecompression {
}

mutating func decompress(part: inout ByteBuffer, buffer: inout ByteBuffer, originalLength: Int) throws {
buffer.reserveCapacity(part.readableBytes * 2)

self.inflated += try self.stream.inflatePart(input: &part, output: &buffer)

if self.limit.exceeded(compressed: originalLength, decompressed: self.inflated) {
Expand All @@ -114,6 +112,7 @@ public enum NIOHTTPDecompression {

extension z_stream {
mutating func inflatePart(input: inout ByteBuffer, output: inout ByteBuffer) throws -> Int {
let minimumCapacity = input.readableBytes * 2
var written = 0
try input.readWithUnsafeMutableReadableBytes { pointer in
self.avail_in = UInt32(pointer.count)
Expand All @@ -126,15 +125,15 @@ extension z_stream {
self.next_out = nil
}

written += try self.inflatePart(to: &output)
written += try self.inflatePart(to: &output, minimumCapacity: minimumCapacity)

return pointer.count - Int(self.avail_in)
}
return written
}

private mutating func inflatePart(to buffer: inout ByteBuffer) throws -> Int {
return try buffer.writeWithUnsafeMutableBytes { pointer in
private mutating func inflatePart(to buffer: inout ByteBuffer, minimumCapacity: Int) throws -> Int {
return try buffer.writeWithUnsafeMutableBytes(minimumWritableBytes: minimumCapacity) { pointer in
self.avail_out = UInt32(pointer.count)
self.next_out = CNIOExtrasZlib_voidPtr_to_BytefPtr(pointer.baseAddress!)

Expand Down
2 changes: 1 addition & 1 deletion Sources/NIOHTTPCompression/HTTPResponseCompressor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ private extension z_stream {
private mutating func deflateToBuffer(buffer: inout ByteBuffer, flag: Int32) -> Int32 {
var rc = Z_OK

buffer.writeWithUnsafeMutableBytes { outputPtr in
buffer.writeWithUnsafeMutableBytes(minimumWritableBytes: buffer.capacity) { outputPtr in
let typedOutputPtr = UnsafeMutableBufferPointer(start: outputPtr.baseAddress!.assumingMemoryBound(to: UInt8.self),
count: outputPtr.count)
self.avail_out = UInt32(typedOutputPtr.count)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ class HTTPRequestDecompressorTest: XCTestCase {
stream.avail_in = UInt32(typedDataPtr.count)
stream.next_in = typedDataPtr.baseAddress!

buffer.writeWithUnsafeMutableBytes { outputPtr in
buffer.writeWithUnsafeMutableBytes(minimumWritableBytes: 0) { outputPtr in
let typedOutputPtr = UnsafeMutableBufferPointer(start: outputPtr.baseAddress!.assumingMemoryBound(to: UInt8.self),
count: outputPtr.count)
stream.avail_out = UInt32(typedOutputPtr.count)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ private extension ByteBuffer {

@discardableResult
mutating func writeWithUnsafeMutableUInt8Bytes(_ body: (UnsafeMutableBufferPointer<UInt8>) throws -> Int) rethrows -> Int {
return try self.writeWithUnsafeMutableBytes { (ptr: UnsafeMutableRawBufferPointer) -> Int in
return try self.writeWithUnsafeMutableBytes(minimumWritableBytes: 0) { (ptr: UnsafeMutableRawBufferPointer) -> Int in
let baseInputPointer = ptr.baseAddress?.assumingMemoryBound(to: UInt8.self)
let inputBufferPointer = UnsafeMutableBufferPointer(start: baseInputPointer, count: ptr.count)
return try body(inputBufferPointer)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ class HTTPResponseDecompressorTest: XCTestCase {
stream.avail_in = UInt32(typedDataPtr.count)
stream.next_in = typedDataPtr.baseAddress!

buffer.writeWithUnsafeMutableBytes { outputPtr in
buffer.writeWithUnsafeMutableBytes(minimumWritableBytes: 0) { outputPtr in
let typedOutputPtr = UnsafeMutableBufferPointer(start: outputPtr.baseAddress!.assumingMemoryBound(to: UInt8.self),
count: outputPtr.count)
stream.avail_out = UInt32(typedOutputPtr.count)
Expand Down

0 comments on commit ed97628

Please sign in to comment.