             let destinationFileModifiedDate = (try? fileManager.attributesOfItemAtPath(destinationPath)[NSFileModificationDate]) as? NSDate
             if (destinationFileModifiedDate == nil) || (bundleFileModifiedDate.compare(destinationFileModifiedDate!) == .OrderedDescending) {
                 let bundleText = try String(contentsOfFile: bundlePath)
-                try replaceText(bundleText, replacingTexts: replacingTexts).writeToFile(destinationPath, atomically: true, encoding: NSUTF8StringEncoding)
+                try replaceText(bundleText, replacingTexts: replacingTexts).writeToFile(destinationPath, atomically: true, encoding: encoding)
                 destinationText = try String(contentsOfFile: destinationPath)
                 didReplaceFile?(destinationURL: destinationURL, error: nil)
             } else {

                    return
            }
            
            let text = replaceText(String(data: data, encoding: NSUTF8StringEncoding) ?? "", replacingTexts: replacingTexts)
            if !text.isEmpty && (text != destinationText) {
                do {
                    try text.writeToFile(destinationPath, atomically: true, encoding: NSUTF8StringEncoding)
                    didReplaceFile?(destinationURL: destinationURL, error: nil)
                } catch let error as NSError {
                    didReplaceFile?(destinationURL: destinationURL, error: error)

                    return completion("download for file '\(filepath)' failed with error: \(error)")
            }
            
            let text = String(data: data, encoding: encoding) ?? ""
            let destinationText = try? String(contentsOfFile: filepath) ?? ""
            
            if !text.isEmpty && (text != destinationText) {
                do {
                    try text.writeToFile(filepath, atomically: true, encoding: encoding)
                    completion("successfully updated file '\(filepath)'")
                } catch let error as NSError {
                    completion("writing to file '\(filepath)' failed with error: \(error)")
