marinofaggiana hace 4 años
padre
commit
8ba0e1800b
Se han modificado 1 ficheros con 6 adiciones y 23 borrados
  1. 6 23
      iOSClient/Utility/NCUtilityFileSystem.swift

+ 6 - 23
iOSClient/Utility/NCUtilityFileSystem.swift

@@ -74,49 +74,32 @@ class NCUtilityFileSystem: NSObject {
     }
     
     // MARK: - Get file data as chunks Methode.
-    func getFileDataInChunks() {
+    func getFileDataInChunks(filePath: String, size: Int = 5) -> [String]? {
         
-        let doumentDirectoryPath = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0] as NSString
-        let filePath = doumentDirectoryPath.appendingPathComponent("video.mp4")
+        let chunkSize = 1024 * 1000 * size
+        let ReadData = NSMutableData()
+        var filenames: [String]?
         
-        
-        //Check file exits at path or not.
         if FileManager.default.fileExists(atPath: filePath) {
-            
-            let chunkSize = 1024 // divide data into 1 kb
-            
-            //Create NSMutableData object to save read data.
-            let ReadData = NSMutableData()
-            
             do {
-                
-                //open file for reading.
                 let outputFileHandle = try FileHandle(forReadingFrom: URL(fileURLWithPath: filePath))
-                
-                // get the first chunk
                 var datas = outputFileHandle.readData(ofLength: chunkSize)
                 
-                //check next chunk is empty or not.
                 while !(datas.isEmpty) {
-                    
-                    //here I write chunk data to ReadData or you can directly write to socket.
                     ReadData.append(datas)
-                    
-                    // get the next chunk
                     datas = outputFileHandle.readData(ofLength: chunkSize)
-                    
                     print("Running: \(ReadData.length)")
                 }
                 
-                //close outputFileHandle after reading data complete.
                 outputFileHandle.closeFile()
-                
                 print("File reading complete")
                 
             }catch let error as NSError {
                 print("Error : \(error.localizedDescription)")
             }
         }
+        
+        return filenames
     }
 }