{-# LANGUAGE OverloadedStrings #-}{-# LANGUAGE FlexibleContexts #-}moduleNetwork.URI.Conduit.File(decodeString,fileScheme,toFilePath)whereimportPreludehiding(catch,FilePath)importNetwork.URI(unEscapeString)importNetwork.URI.ConduitimportqualifiedFilesystem.Path.CurrentOSasFPimportqualifiedData.TextasTimportqualifiedData.SetasSetimportqualifiedData.ConduitasCimportqualifiedData.Conduit.BinaryasCBimportqualifiedFilesystemasFimportControl.Monad.IO.Class(liftIO)importqualifiedData.ByteStringasS-- | Converts a string, such as a command-line argument, into a URI. First-- tries to parse as an absolute URI. If this fails, it interprets as a-- relative or absolute filepath.decodeString::String->IOURIdecodeStrings=caseparseURI$T.packsofJustu->returnuNothing->dowd<-F.getWorkingDirectoryletfp=wdFP.</>FP.decodeStringsparseURI$T.append"file://"$T.concatMapfixSpace$T.mapfixSlash$eitheridid$FP.toTextfpwherefixSlash'\\'='/'fixSlashc=cfixSpace' '="%20"fixSpacec=T.singletoncfileScheme::SchemefileScheme=Scheme{schemeNames=Set.singleton"file:",schemeReader=Just$sourceFile.toFilePath,schemeWriter=Just$\uri->C.Sink$doletfp=toFilePathuriliftIO$F.createTree$FP.directoryfpC.prepareSink$CB.sinkFile(FP.encodeStringfp)}toFilePath::URI->FP.FilePathtoFilePathuri=FP.fromText$caseuriAuthorityuriofNothing->uriPathuriJusta->T.concat[uriRegNamea,uriPorta,T.pack$unEscapeString$T.unpack$uriPathuri]sourceFile::C.ResourceIOm=>FP.FilePath->C.SourcemS.ByteStringsourceFile=CB.sourceFile.FP.encodeString