diff --git a/AMSMB2/FileHandle.swift b/AMSMB2/FileHandle.swift index b9d3d05..2ccbcad 100644 --- a/AMSMB2/FileHandle.swift +++ b/AMSMB2/FileHandle.swift @@ -111,34 +111,25 @@ final class SMB2FileHandle { precondition(length <= UInt32.max, "Length bigger than UInt32.max can't be handled by libsmb2.") let bufSize = length > 0 ? length : optimizedReadSize - var buffer = UnsafeMutablePointer.allocate(capacity: bufSize) + let buffer = UnsafeMutablePointer.allocate(capacity: bufSize) buffer.initialize(repeating: 0, count: bufSize) - defer { - buffer.deinitialize(count: bufSize) - buffer.deallocate() - } - let (result, _) = try context.async_await(defaultError: .EIO) { (context, cbPtr) -> Int32 in smb2_read_async(context, handle, buffer, UInt32(bufSize), SMB2Context.async_handler, cbPtr) } - return Data(bytes: buffer, count: Int(result)) + return Data(bytesNoCopy: buffer, count: Int(result), deallocator: .free) } func pread(offset: UInt64, length: Int = 0) throws -> Data { precondition(length <= UInt32.max, "Length bigger than UInt32.max can't be handled by libsmb2.") let bufSize = length > 0 ? length : optimizedReadSize - var buffer = UnsafeMutablePointer.allocate(capacity: bufSize) + let buffer = UnsafeMutablePointer.allocate(capacity: bufSize) buffer.initialize(repeating: 0, count: bufSize) - defer { - buffer.deinitialize(count: bufSize) - buffer.deallocate() - } let (result, _) = try context.async_await(defaultError: .EIO) { (context, cbPtr) -> Int32 in smb2_pread_async(context, handle, buffer, UInt32(bufSize), offset, SMB2Context.async_handler, cbPtr) } - return Data(bytes: buffer, count: Int(result)) + return Data(bytesNoCopy: buffer, count: Int(result), deallocator: .free) } var maxWriteSize: Int { diff --git a/README.md b/README.md index 55e402b..3b8b76b 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ Or add this to Cartfile: github "amosavian/AMSMB2" ``` -###Manually +### Manually To have latest updates with ease, use this command on terminal to get a clone: