Use
encodeFiles : List ( FileRecord, Data ) -> Encode.Encoderto tar an arbitrary set of files which may contain either text or binary data. To tar a set of text files, you can use
encodeTextFiles : List (FileRecord, String) -> Encode.EncoderFor more details, see the README. See also the demo app ./examples/Main.elm
A FileRecord contains the information needed for
tar to construct the header for the assoicated file
in the tar archive. You may use defaultFileRecord as
a starting point, modifying only what is needed.
Example
fileRecord_ =
Tar.defaultFileRecord
fileRecord1 =
{ fileRecord_ | filename = "a.txt" }
content1 =
"One two three\n"
fileRecord2 =
{ fileRecord_ | filename = "c.binary" }
content2 =
Hex.toBytes "616263646566" |> Maybe.withDefault (encode (Bytes.Encode.unsignedInt8 0))
Tar.encodeFiles
[ ( fileRecord1, StringData content1 )
, ( fileRecord2, BinaryData content2 )
]
|> Bytes.Encode.encode
Note: `Hex` is found in `jxxcarlson/hex`Example
encodeFiles [(defaultFileRecord, "This is a test"), (defaultFileRecord, "Lah di dah do day!")] |> Bytes.Encode.encode == <2594 bytes> : Bytes
defaultFileRecord is a dummy FileRecord that you modify to suit your needs. It contains a lot of boilerplates
Example
fileRecord = { defaultFileRecord | filename = "Test.txt" }
See the definition of FileRecord to see what other fields you
may want to modify, or see /examples/Main.elm.
Use
StringData Stringfor text data,BinaryData Bytesfor binary data, e.g.,StringData "This is a test"orBinaryData someBytes