diff options
Diffstat (limited to 'src/Storage.hs')
-rw-r--r-- | src/Storage.hs | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/src/Storage.hs b/src/Storage.hs index 52cda85..e610faa 100644 --- a/src/Storage.hs +++ b/src/Storage.hs @@ -245,8 +245,7 @@ serializeRecItem name (RecInt x) = [name, BC.pack ":i", BC.singleton ' ', BC.pac serializeRecItem name (RecNum x) = [name, BC.pack ":n", BC.singleton ' ', BC.pack (showRatio x), BC.singleton '\n'] serializeRecItem name (RecText x) = [name, BC.pack ":t", BC.singleton ' ', escaped, BC.singleton '\n'] where escaped = BC.concatMap escape $ encodeUtf8 x - escape '\\' = BC.pack "\\\\" - escape '\n' = BC.pack "\\n" + escape '\n' = BC.pack "\n\t" escape c = BC.singleton c serializeRecItem name (RecBinary x) = [name, BC.pack ":b ", convertToBase Base64 x, BC.singleton '\n'] serializeRecItem name (RecDate x) = [name, BC.pack ":d", BC.singleton ' ', BC.pack (formatTime defaultTimeLocale "%s %z" x), BC.singleton '\n'] @@ -283,7 +282,7 @@ unsafeDeserializeObject st bytes = (,next) <$> case otype of _ | otype == BC.pack "blob" -> return $ Blob content | otype == BC.pack "rec" -> maybe (throwError $ "Malformed record item ") - (return . Rec) $ sequence $ map parseRecLine $ BC.lines content + (return . Rec) $ sequence $ map parseRecLine $ mergeCont [] $ BC.lines content | otherwise -> throwError $ "Unknown object type" _ -> throwError $ "Malformed object" where splitObjPrefix line = do @@ -292,6 +291,10 @@ unsafeDeserializeObject st bytes = guard $ BL.null rest return (BL.toStrict otype, len) + mergeCont cs (a:b:rest) | Just ('\t', b') <- BC.uncons b = mergeCont (b':BC.pack "\n":cs) (a:rest) + mergeCont cs (a:rest) = B.concat (a : reverse cs) : mergeCont [] rest + mergeCont _ [] = [] + parseRecLine line = do colon <- BC.elemIndex ':' line space <- BC.elemIndex ' ' line |