packages feed

debug-dump 0.1.0.2 → 0.1.1.0

raw patch · 3 files changed

+45/−3 lines, 3 filesdep +directorydep +randomPVP ok

version bump matches the API change (PVP)

Dependencies added: directory, random

API changes (from Hackage documentation)

+ Debug.Trace.Dump: traceBSLSuffix :: String -> ByteString -> a -> a
+ Debug.Trace.Dump: traceTextSuffix :: String -> Text -> a -> a

Files

CHANGELOG.md view
@@ -1,5 +1,9 @@ # debug-dump +## 0.1.1.0++  * Add `traceBSLSuffix` and `traceTextSuffix`+ ## 0.1.0.2    * Revert unnecessary strictness
debug-dump.cabal view
@@ -1,6 +1,6 @@ cabal-version: 1.18 name: debug-dump-version: 0.1.0.2+version: 0.1.1.0 license: BSD3 license-file: LICENSE copyright: Copyright: (c) 2019 Vanessa McHale@@ -34,7 +34,9 @@     build-depends:         base >=4.7 && <5,         text -any,-        bytestring -any+        bytestring -any,+        random >=1.0.1.0,+        directory -any      if flag(development)         ghc-options: -Werror
src/Debug/Trace/Dump.hs view
@@ -2,13 +2,49 @@     ( traceFile     , traceFileBSL     , traceFileText+    , traceBSLSuffix+    , traceTextSuffix     ) where +import           Control.Applicative  (pure) import qualified Data.ByteString.Lazy as BSL-import           Data.Functor         (($>))+import           Data.Functor         (($>), (<$>)) import qualified Data.Text            as T import qualified Data.Text.IO         as TIO+import           Data.Word            (Word)+import           Numeric              (showHex)+import           System.Directory     (doesFileExist) import           System.IO.Unsafe     (unsafePerformIO)+import           System.Random        (randomIO)++randHex :: IO String+randHex = ($"") . (showHex :: Word -> ShowS) <$> randomIO++-- | This is a utility function that enables dumping data from multiple+-- function calls without overwriting anything.+traceBSLSuffix :: String -- ^ File extension, e.g. @.json@+               -> BSL.ByteString+               -> a+               -> a+traceBSLSuffix ext bytes x = unsafePerformIO $ do+    fpBase <- randHex+    let fp = fpBase ++ ext+    check <- doesFileExist fp+    if check+        then pure $ traceBSLSuffix ext bytes x+        else BSL.writeFile fp bytes $> x++traceTextSuffix :: String -- ^ File extension, e.g. @.json@+                -> T.Text+                -> a+                -> a+traceTextSuffix ext txt x = unsafePerformIO $ do+    fpBase <- randHex+    let fp = fpBase ++ ext+    check <- doesFileExist fp+    if check+        then pure $ traceTextSuffix ext txt x+        else TIO.writeFile fp txt $> x  traceFileBSL :: FilePath -> BSL.ByteString -> a -> a traceFileBSL fp bytes x = unsafePerformIO $