fix NIO 2.9.0 deprecations (#61)

Motivation:

Usage of deprecated methods is bad.

Modification:

Fix usage of deprecated methods.

Result:

Fewer warnings.
This commit is contained in:
Artem Redkin authored and Johannes Weiss committed 2019-10-23 17:23:34 -07:00
1 parent 0584020dca
commit ed97628fa3
6 files changed
+9 -10

No files matched your search

+1 -1
View File
@@ -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
)
@@ -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) {
@@ -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)
@@ -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!)
@@ -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)
@@ -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)
@@ -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)
@@ -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)