77
88import Foundation
99
10- /// Represents an individual log file on disk used as part of a
11- /// LogRotation
12- final class LogFile {
13- let fileURL : URL
14- let sizeLimitInBytes : UInt64
10+ /// Represents an individual log file on disk used as part of a LogRotation.
11+ package final class LogFile {
12+ package let fileURL : URL
13+ package let sizeLimitInBytes : UInt64
1514
1615 private let handle : FileHandle
1716 private var count : UInt64
1817
1918 /// Creates a new file with the given URL and sets its attributes accordingly.
20- init ( forWritingTo fileURL: URL , sizeLimitInBytes: UInt64 ) throws {
19+ package init ( forWritingTo fileURL: URL , sizeLimitInBytes: UInt64 ) throws {
2120 self . fileURL = fileURL
2221 self . sizeLimitInBytes = sizeLimitInBytes
2322 self . handle = try FileHandle ( forWritingTo: fileURL)
2423 self . count = 0
2524 }
2625
2726 /// Opens a file for updating with the given URL and sets its attributes accordingly.
28- init ( forAppending fileURL: URL , sizeLimitInBytes: UInt64 ) throws {
27+ package init ( forAppending fileURL: URL , sizeLimitInBytes: UInt64 ) throws {
2928 self . fileURL = fileURL
3029 self . sizeLimitInBytes = sizeLimitInBytes
3130 self . handle = try FileHandle ( forUpdating: fileURL)
@@ -41,7 +40,7 @@ final class LogFile {
4140 }
4241
4342 /// Returns the number of bytes available in the underlying file.
44- var available : UInt64 {
43+ package var available : UInt64 {
4544 if sizeLimitInBytes > count {
4645 return sizeLimitInBytes - count
4746 } else {
@@ -50,23 +49,22 @@ final class LogFile {
5049 }
5150
5251 /// Attempts to close the underlying log file.
53- func close( ) throws {
52+ package func close( ) throws {
5453 try handle. close ( )
5554 }
5655
57- /// Atempts to flush the receivers contents to disk.
58- func synchronize( ) throws {
56+ /// Attempts to flush the receivers contents to disk.
57+ package func synchronize( ) throws {
5958 try handle. synchronize ( )
6059 }
6160
6261 /// - Returns: true if writing to the underlying log file will keep its size below the limit.
63- func hasSpace( for data: Data ) -> Bool {
62+ package func hasSpace( for data: Data ) -> Bool {
6463 return UInt64 ( data. count) <= available
6564 }
6665
67- /// Writes the given **single line of text** represented as a
68- /// Data to the underlying log file.
69- func write( data: Data ) throws {
66+ /// Writes the given data to the underlying log file.
67+ package func write( data: Data ) throws {
7068 if #available( macOS 12 . 0 , iOS 13 . 4 , watchOS 6 . 2 , tvOS 13 . 4 , * ) {
7169 try handle. write ( contentsOf: data)
7270 } else {
@@ -75,5 +73,4 @@ final class LogFile {
7573 try handle. synchronize ( )
7674 count = count + UInt64( data. count) // swiftlint:disable:this shorthand_operator
7775 }
78-
7976}
0 commit comments