Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jgm/hsb2hs
Preprocessor for inserting literals with binary blobs into Haskell programs.
https://github.com/jgm/hsb2hs
Last synced: 26 days ago
JSON representation
Preprocessor for inserting literals with binary blobs into Haskell programs.
- Host: GitHub
- URL: https://github.com/jgm/hsb2hs
- Owner: jgm
- License: bsd-3-clause
- Created: 2010-08-03T07:38:50.000Z (over 14 years ago)
- Default Branch: master
- Last Pushed: 2015-11-15T20:26:29.000Z (almost 9 years ago)
- Last Synced: 2024-05-09T14:05:55.307Z (6 months ago)
- Language: Haskell
- Homepage:
- Size: 164 KB
- Stars: 11
- Watchers: 5
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.markdown
- License: LICENSE
Awesome Lists containing this project
README
hsb2hs
======hsb2hs is a preprocessor that allows you to include binary blobs as
literals in your Haskell programs and libraries. Running hsb2hs on
a file containingfoo :: ByteString
foo = %blob "data/foo.txt"will produce a file containing
foo :: ByteString
foo = "here's my data"where data/foo.txt is a text file containing the string
"here's my data." (Note that the literal `"here's my data"`
can be interpreted either as a String or, with OverloadedStrings,
as a ByteString.)If you have a whole directory of data files, you can get an
association list instead:bar :: [(FilePath, ByteString)]
bar = %blob "images"hsb2hs is set up to use as a preprocessor in the Haskell build
procedure. Put your blob instructions in .hsb files, and Cabal will
automatically convert these to .hs files during the build.
To use hsb2hs with Cabal, set Build-type to `Custom' and use something
like the following for your `Setup.hs`:``` haskell
import Distribution.Simple
import Distribution.Simple.PreProcess
import Distribution.Simple.Utils (info)
import System.Directory
import System.Process
import System.Exitmain :: IO ()
main = defaultMainWithHooks simpleUserHooks{
hookedPreProcessors = [ppBlobSuffixHandler]
}ppBlobSuffixHandler :: PPSuffixHandler
ppBlobSuffixHandler = ("hsb", \_ _ ->
PreProcessor {
platformIndependent = True,
runPreProcessor = mkSimplePreProcessor $ \infile outfile verbosity ->
do info verbosity $ "Preprocessing " ++ infile ++ " to " ++ outfile
hsb2hsPath <- findExecutable "hsb2hs"
case hsb2hsPath of
Just p -> rawSystem p [infile, infile, outfile]
Nothing -> error "hsb2hs is needed to build this program."
return ()})
```