@@ -12,6 +12,7 @@ import SwiftShell
1212
1313public extension File {
1414
15+ /// Appending suffix to file name
1516 func nameWithSuffix( _ suffix: String ) -> String {
1617 if let unwrappedExtension = `extension` {
1718 return nameExcludingExtension + suffix + " . " + unwrappedExtension
@@ -21,9 +22,8 @@ public extension File {
2122 }
2223 }
2324
24- ////////////////////////////////////////////////////////////////////////////////
25- // MARK: - Duplication
26-
25+
26+ /// Create file duplicate
2727 @discardableResult func createDuplicate( withName newName: String , keepExtension: Bool = true , overwrite: Bool = true ) throws -> File ? {
2828 if !overwrite && FileManager . default. fileExists ( atPath: newName) { return nil }
2929
@@ -53,9 +53,8 @@ public extension File {
5353 }
5454 }
5555
56- ////////////////////////////////////////////////////////////////////////////////
57- // MARK: - Modification date
58-
56+
57+ /// File modification date
5958 func modificationDate( ) throws -> Date {
6059
6160 let fileAttributes = try FileManager . default. attributesOfItem ( atPath: path) as [ FileAttributeKey : Any ]
@@ -64,9 +63,8 @@ public extension File {
6463 return modificationDate
6564 }
6665
67- ////////////////////////////////////////////////////////////////////////////////
68- // MARK: - Tag file
6966
67+ /// Tag file with date/time/version signature
7068 func tag( copy: Bool ) throws {
7169 let date = try modificationDate ( )
7270 let suffix = ScriptToolkit . dateFormatter. string ( from: date)
@@ -92,6 +90,7 @@ public extension File {
9290 ////////////////////////////////////////////////////////////////////////////////
9391 // MARK: - Photo Processing
9492
93+ /// Moving file to appropriate folder during photo processing
9594 func incorporateFile( using folderRecords: [ ( Folder , [ Int ] ) ] ) throws {
9695 print ( " \( path) " )
9796 let numberString = nameExcludingExtension. replacingOccurrences ( of: " IMG_ " , with: " " )
@@ -124,6 +123,7 @@ public extension File {
124123 ////////////////////////////////////////////////////////////////////////////////
125124 // MARK: - Resize image
126125
126+ /// Image resizing
127127 @discardableResult func resizeImage( newName: String , size: CGSize , overwrite: Bool = true ) throws -> File {
128128 let image : NSImage ? = NSImage ( contentsOfFile: self . path)
129129 let newImage = image. map { try ? $0. copy ( size: size) } ?? nil
@@ -135,6 +135,7 @@ public extension File {
135135 return try File ( path: newName)
136136 }
137137
138+ /// Create three sizes of image for iOS asset
138139 func resizeAt123x( width: Int , height: Int , outputDir: Folder , overwrite: Bool = true ) throws {
139140 print ( name)
140141
@@ -151,6 +152,7 @@ public extension File {
151152 ////////////////////////////////////////////////////////////////////////////////
152153 // MARK: - Audio Processing
153154
155+ /// Slow down audio
154156 @discardableResult func slowDownAudio( newName: String , percent: Float , overwrite: Bool = true ) throws -> File {
155157 if FileManager . default. fileExists ( atPath: newName) {
156158 if !overwrite { return try File ( path: newName) }
@@ -161,6 +163,7 @@ public extension File {
161163 return try File ( path: newName)
162164 }
163165
166+ /// Conversion to .wav
164167 @discardableResult func convertToWav( newName: String , overwrite: Bool = true ) throws -> File {
165168 if FileManager . default. fileExists ( atPath: newName) {
166169 if !overwrite { return try File ( path: newName) }
@@ -171,6 +174,7 @@ public extension File {
171174 return try File ( path: newName)
172175 }
173176
177+ /// Sample rate normalization
174178 @discardableResult func normalizeSampleRate( newName: String , overwrite: Bool = true ) throws -> File {
175179 if FileManager . default. fileExists ( atPath: newName) {
176180 if !overwrite { return try File ( path: newName) }
@@ -180,7 +184,8 @@ public extension File {
180184 runAndDebug ( ScriptToolkit . soxPath, path, " -r " , " 44100 " , " --channels " , " 2 " , newName)
181185 return try File ( path: newName)
182186 }
183-
187+
188+ /// Conversion to .m4a
184189 @discardableResult func convertToM4A( newName: String , overwrite: Bool = true ) throws -> File {
185190 if FileManager . default. fileExists ( atPath: newName) {
186191 if !overwrite { return try File ( path: newName) }
@@ -191,6 +196,7 @@ public extension File {
191196 return try File ( path: newName)
192197 }
193198
199+ /// Add a 5s silence and the begining of audio file
194200 @discardableResult func addSilence( newName: String , overwrite: Bool = true ) throws -> File {
195201 if FileManager . default. fileExists ( atPath: newName) {
196202 if !overwrite { return try File ( path: newName) }
@@ -201,6 +207,7 @@ public extension File {
201207 return try File ( path: newName)
202208 }
203209
210+ /// Prepare song for practise - generate audio in 50%, 75%, 90% and 100% speed
204211 func prepareSongForPractise( outputFolder: Folder , overwrite: Bool = true ) throws {
205212 let inputFolder = parent!
206213
@@ -275,6 +282,7 @@ public extension File {
275282 ////////////////////////////////////////////////////////////////////////////////
276283 // MARK: - Video Processing
277284
285+ /// Video reduction to smaller size and quality
278286 @discardableResult func reduceVideo( newName: String , overwrite: Bool = true ) throws -> File {
279287 if FileManager . default. fileExists ( atPath: newName) {
280288 if !overwrite { return try File ( path: newName) }
@@ -288,6 +296,7 @@ public extension File {
288296 ////////////////////////////////////////////////////////////////////////////////
289297 // MARK: - PDF
290298
299+ /// Crop margins from PDF
291300 @discardableResult func cropPDF( newName: String , insets: NSEdgeInsets , overwrite: Bool = true ) throws -> File {
292301 if FileManager . default. fileExists ( atPath: newName) {
293302 if !overwrite { return try File ( path: newName) }
0 commit comments