Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Sources/ZIPFoundation/Archive+BackingConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ import Foundation
extension Archive {

struct BackingConfiguration {
let file: UnsafeMutablePointer<FILE>
let file: FILEPointer
let endOfCentralDirectoryRecord: EndOfCentralDirectoryRecord
let zip64EndOfCentralDirectory: ZIP64EndOfCentralDirectory?
#if swift(>=5.0)
let memoryFile: MemoryFile?

init(file: UnsafeMutablePointer<FILE>,
init(file: FILEPointer,
endOfCentralDirectoryRecord: EndOfCentralDirectoryRecord,
zip64EndOfCentralDirectory: ZIP64EndOfCentralDirectory? = nil,
memoryFile: MemoryFile? = nil) {
Expand All @@ -30,7 +30,7 @@ extension Archive {
}
#else

init(file: UnsafeMutablePointer<FILE>,
init(file: FILEPointer,
endOfCentralDirectoryRecord: EndOfCentralDirectoryRecord,
zip64EndOfCentralDirectory: ZIP64EndOfCentralDirectory?) {
self.file = file
Expand Down
6 changes: 3 additions & 3 deletions Sources/ZIPFoundation/Archive+MemoryFile.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ class MemoryFile {
self.data = data
}

func open(mode: String) -> UnsafeMutablePointer<FILE>? {
func open(mode: String) -> FILEPointer? {
let cookie = Unmanaged.passRetained(self)
let writable = mode.count > 0 && (mode.first! != "r" || mode.last! == "+")
let append = mode.count > 0 && mode.first! == "a"
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS) || os(Android)
let result = writable
? funopen(cookie.toOpaque(), readStub, writeStub, seekStub, closeStub)
: funopen(cookie.toOpaque(), readStub, nil, seekStub, closeStub)
Expand Down Expand Up @@ -99,7 +99,7 @@ private func closeStub(_ cookie: UnsafeMutableRawPointer?) -> Int32 {
return 0
}

#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS) || os(Android)
private func readStub(_ cookie: UnsafeMutableRawPointer?,
_ bytePtr: UnsafeMutablePointer<Int8>?,
_ count: Int32) -> Int32 {
Expand Down
2 changes: 1 addition & 1 deletion Sources/ZIPFoundation/Archive+Reading.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ extension Archive {
}
try fileManager.createParentDirectoryStructure(for: url)
let destinationRepresentation = fileManager.fileSystemRepresentation(withPath: url.path)
guard let destinationFile: UnsafeMutablePointer<FILE> = fopen(destinationRepresentation, "wb+") else {
guard let destinationFile: FILEPointer = fopen(destinationRepresentation, "wb+") else {
throw CocoaError(.fileNoSuchFile)
}
defer { fclose(destinationFile) }
Expand Down
2 changes: 1 addition & 1 deletion Sources/ZIPFoundation/Archive+Writing.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ extension Archive {
switch type {
case .file:
let entryFileSystemRepresentation = fileManager.fileSystemRepresentation(withPath: fileURL.path)
guard let entryFile: UnsafeMutablePointer<FILE> = fopen(entryFileSystemRepresentation, "rb") else {
guard let entryFile: FILEPointer = fopen(entryFileSystemRepresentation, "rb") else {
throw CocoaError(.fileNoSuchFile)
}
defer { fclose(entryFile) }
Expand Down
6 changes: 3 additions & 3 deletions Sources/ZIPFoundation/Archive.swift
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public final class Archive: Sequence {
public let url: URL
/// Access mode for an archive file.
public let accessMode: AccessMode
var archiveFile: UnsafeMutablePointer<FILE>
var archiveFile: FILEPointer
var endOfCentralDirectoryRecord: EndOfCentralDirectoryRecord
var zip64EndOfCentralDirectory: ZIP64EndOfCentralDirectory?
var preferredEncoding: String.Encoding?
Expand Down Expand Up @@ -267,7 +267,7 @@ public final class Archive: Sequence {

// MARK: - Helpers

static func scanForEndOfCentralDirectoryRecord(in file: UnsafeMutablePointer<FILE>)
static func scanForEndOfCentralDirectoryRecord(in file: FILEPointer)
-> EndOfCentralDirectoryStructure? {
var eocdOffset: UInt64 = 0
var index = minEndOfCentralDirectoryOffset
Expand All @@ -290,7 +290,7 @@ public final class Archive: Sequence {
return nil
}

private static func scanForZIP64EndOfCentralDirectory(in file: UnsafeMutablePointer<FILE>, eocdOffset: UInt64)
private static func scanForZIP64EndOfCentralDirectory(in file: FILEPointer, eocdOffset: UInt64)
-> ZIP64EndOfCentralDirectory? {
guard UInt64(ZIP64EndOfCentralDirectoryLocator.size) < eocdOffset else {
return nil
Expand Down
14 changes: 10 additions & 4 deletions Sources/ZIPFoundation/Data+Serialization.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@

import Foundation

#if os(Android)
public typealias FILEPointer = OpaquePointer
#else
public typealias FILEPointer = UnsafeMutablePointer<FILE>
#endif

protocol DataSerializable {
static var size: Int { get }
init?(data: Data, additionalDataProvider: (Int) throws -> Data)
Expand All @@ -31,7 +37,7 @@ extension Data {
#endif
}

static func readStruct<T>(from file: UnsafeMutablePointer<FILE>, at offset: UInt64)
static func readStruct<T>(from file: FILEPointer, at offset: UInt64)
-> T? where T: DataSerializable {
guard offset <= .max else { return nil }
fseeko(file, off_t(offset), SEEK_SET)
Expand Down Expand Up @@ -68,7 +74,7 @@ extension Data {
return checksum
}

static func readChunk(of size: Int, from file: UnsafeMutablePointer<FILE>) throws -> Data {
static func readChunk(of size: Int, from file: FILEPointer) throws -> Data {
let alignment = MemoryLayout<UInt>.alignment
#if swift(>=4.1)
let bytes = UnsafeMutableRawPointer.allocate(byteCount: size, alignment: alignment)
Expand All @@ -88,7 +94,7 @@ extension Data {
#endif
}

static func write(chunk: Data, to file: UnsafeMutablePointer<FILE>) throws -> Int {
static func write(chunk: Data, to file: FILEPointer) throws -> Int {
var sizeWritten: Int = 0
chunk.withUnsafeBytes { (rawBufferPointer) in
if let baseAddress = rawBufferPointer.baseAddress, rawBufferPointer.count > 0 {
Expand All @@ -104,7 +110,7 @@ extension Data {
}

static func writeLargeChunk(_ chunk: Data, size: UInt64, bufferSize: Int,
to file: UnsafeMutablePointer<FILE>) throws -> UInt64 {
to file: FILEPointer) throws -> UInt64 {
var sizeWritten: UInt64 = 0
chunk.withUnsafeBytes { (rawBufferPointer) in
if let baseAddress = rawBufferPointer.baseAddress, rawBufferPointer.count > 0 {
Expand Down
2 changes: 1 addition & 1 deletion Sources/ZIPFoundation/FileManager+ZIP.swift
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ extension FileManager {
let entryFileSystemRepresentation = fileManager.fileSystemRepresentation(withPath: url.path)
var fileStat = stat()
lstat(entryFileSystemRepresentation, &fileStat)
return Entry.EntryType(mode: fileStat.st_mode)
return Entry.EntryType(mode: mode_t(fileStat.st_mode))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ extension ZIPFoundationTests {
attributes: nil)
XCTAssert(result == true)
let fileSystemRepresentation = fileManager.fileSystemRepresentation(withPath: fileURL.path)
let file: UnsafeMutablePointer<FILE> = fopen(fileSystemRepresentation, "rb")
let file: FILEPointer = fopen(fileSystemRepresentation, "rb")
// Close the file to exercise the error path during readStructure that deals with
// unreadable file data.
fclose(file)
Expand All @@ -38,7 +38,7 @@ extension ZIPFoundationTests {
attributes: nil)
XCTAssert(result == true)
let fileSystemRepresentation = fileManager.fileSystemRepresentation(withPath: fileURL.path)
let file: UnsafeMutablePointer<FILE> = fopen(fileSystemRepresentation, "rb")
let file: FILEPointer = fopen(fileSystemRepresentation, "rb")
// Close the file to exercise the error path during readChunk that deals with
// unreadable file data.
fclose(file)
Expand All @@ -60,7 +60,7 @@ extension ZIPFoundationTests {
attributes: nil)
XCTAssert(result == true)
let fileSystemRepresentation = fileManager.fileSystemRepresentation(withPath: fileURL.path)
let file: UnsafeMutablePointer<FILE> = fopen(fileSystemRepresentation, "rb")
let file: FILEPointer = fopen(fileSystemRepresentation, "rb")
// Close the file to exercise the error path during writeChunk that deals with
// unwritable files.
fclose(file)
Expand Down Expand Up @@ -92,7 +92,7 @@ extension ZIPFoundationTests {
attributes: nil)
XCTAssert(result == true)
let fileSystemRepresentation = fileManager.fileSystemRepresentation(withPath: fileURL.path)
let file: UnsafeMutablePointer<FILE> = fopen(fileSystemRepresentation, "rb+")
let file: FILEPointer = fopen(fileSystemRepresentation, "rb+")
let data = Data.makeRandomData(size: 1024)
do {
let writtenSize = try Data.writeLargeChunk(data, size: 1024, bufferSize: 256, to: file)
Expand All @@ -114,7 +114,7 @@ extension ZIPFoundationTests {
attributes: nil)
XCTAssert(result == true)
let fileSystemRepresentation = fileManager.fileSystemRepresentation(withPath: fileURL.path)
let file: UnsafeMutablePointer<FILE> = fopen(fileSystemRepresentation, "rb")
let file: FILEPointer = fopen(fileSystemRepresentation, "rb")
let data = Data.makeRandomData(size: 1024)
// Close the file to exercise the error path during writeChunk that deals with
// unwritable files.
Expand Down
2 changes: 1 addition & 1 deletion Tests/ZIPFoundationTests/ZIPFoundationReadingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ extension ZIPFoundationTests {
let archiveURL = self.resourceURL(for: #function, pathExtension: "zip")
let fileManager = FileManager()
let destinationFileSystemRepresentation = fileManager.fileSystemRepresentation(withPath: archiveURL.path)
let destinationFile: UnsafeMutablePointer<FILE> = fopen(destinationFileSystemRepresentation, "r+b")
let destinationFile: FILEPointer = fopen(destinationFileSystemRepresentation, "r+b")

do {
fseek(destinationFile, 64, SEEK_SET)
Expand Down
2 changes: 1 addition & 1 deletion Tests/ZIPFoundationTests/ZIPFoundationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ class ZIPFoundationTests: XCTestCase {
}

func runWithFileDescriptorLimit(_ limit: UInt64, handler: () -> Void) {
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS) || os(Android)
let fileNoFlag = RLIMIT_NOFILE
#else
let fileNoFlag = Int32(RLIMIT_NOFILE.rawValue)
Expand Down