 import PerfectLib
 import PerfectNet
 import Foundation
-	
+
+#if os(Linux)
+import LinuxBridge
+#endif
+
 extension String {
 	var pathExtension: String {
 		return URL(fileURLWithPath: self).pathExtension ?? ""

				}
				return self.sendFile(remainingBytes: rangeCount, response: response, file: file) {
					ok in
					
					file.close()
					response.completed()
				}

			} else {
				completion(false)
			}
		#endif
		}
	}

	// bytes=0-3/7-9/10-15
	func parseRangeHeader(fromHeader header: String, max: Int) -> [Range<Int>] {
		let initialSplit = header.characters.split(separator: "=")
		guard initialSplit.count == 2 && String(initialSplit[0]) == "bytes" else {
			return [Range<Int>]()
		}

		let ranges = initialSplit[1]
		return ranges.split(separator: "/").flatMap { self.parseOneRange(fromString: String($0), max: max) }
	}

	// 0-3
	// 0-
	func parseOneRange(fromString string: String, max: Int) -> Range<Int>? {
		let split = string.characters.split(separator: "-")

		if split.count == 1 {
			guard let lower = Int(String(split[0])) else {
				return nil
			}
			return Range(uncheckedBounds: (lower, max))
		}

		guard let lower = Int(String(split[0])), let upper = Int(String(split[1])) else {
			return nil
		}

		return Range(uncheckedBounds: (lower, upper+1))
	}
}
