more OsPath conversion
Sponsored-by: Brock Spratlen
This commit is contained in:
parent
c69e57aede
commit
474cf3bc8b
38 changed files with 342 additions and 330 deletions
|
@ -9,16 +9,16 @@
|
|||
|
||||
module Types.Direction where
|
||||
|
||||
import qualified Data.ByteString as B
|
||||
import Data.ByteString.Short
|
||||
|
||||
data Direction = Upload | Download
|
||||
deriving (Eq, Ord, Show, Read)
|
||||
|
||||
formatDirection :: Direction -> B.ByteString
|
||||
formatDirection :: Direction -> ShortByteString
|
||||
formatDirection Upload = "upload"
|
||||
formatDirection Download = "download"
|
||||
|
||||
parseDirection :: B.ByteString -> Maybe Direction
|
||||
parseDirection :: ShortByteString -> Maybe Direction
|
||||
parseDirection "upload" = Just Upload
|
||||
parseDirection "download" = Just Download
|
||||
parseDirection _ = Nothing
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
module Types.Transitions where
|
||||
|
||||
import Utility.RawFilePath
|
||||
import Utility.OsPath
|
||||
|
||||
import qualified Data.ByteString.Lazy as L
|
||||
import Data.ByteString.Builder
|
||||
|
@ -16,4 +16,4 @@ data FileTransition
|
|||
= ChangeFile Builder
|
||||
| PreserveFile
|
||||
|
||||
type TransitionCalculator = RawFilePath -> L.ByteString -> FileTransition
|
||||
type TransitionCalculator = OsPath -> L.ByteString -> FileTransition
|
||||
|
|
|
@ -65,6 +65,14 @@ instance ToUUID SB.ShortByteString where
|
|||
| SB.null b = NoUUID
|
||||
| otherwise = UUID (SB.fromShort b)
|
||||
|
||||
-- OsPath is a ShortByteString internally, so this is the most
|
||||
-- efficient conversion.
|
||||
instance FromUUID OsPath where
|
||||
fromUUID s = toOsPath (fromUUID s :: SB.ShortByteString)
|
||||
|
||||
instance ToUUID OsPath where
|
||||
toUUID s = toUUID (fromOsPath s :: SB.ShortByteString)
|
||||
|
||||
instance FromUUID String where
|
||||
fromUUID s = decodeBS (fromUUID s)
|
||||
|
||||
|
@ -102,9 +110,6 @@ buildUUID NoUUID = mempty
|
|||
isUUID :: String -> Bool
|
||||
isUUID = isJust . U.fromString
|
||||
|
||||
uuidPath :: UUID -> OsPath
|
||||
uuidPath u = toOsPath (fromUUID u :: SB.ShortByteString)
|
||||
|
||||
-- A description of a UUID.
|
||||
newtype UUIDDesc = UUIDDesc B.ByteString
|
||||
deriving (Eq, Sem.Semigroup, Monoid, IsString)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue