Use
createArchive : List ( MetaData, Data ) -> Bytesto create4 a tar archive from arbitrary set of files which may contain either text or binary data. To extract files from an archive, imitate this example:
extractArchive testArchiveFor more details, see the README. See also the demo app ./examples/Main.elm
A MetaData value contains the information, e.g.,
file name and file length, needed to construct the header
for a file in the tar archive. You may use defaultMetadata as
a starting point, modifying only what is needed.
Example:
> data1 = ( { defaultMetadata | filename = "one.txt" }, StringData "One" )
> data2 = ( { defaultMetadata | filename = "two.txt" }, StringData "Two" )
> createArchive [data1, data2]
> createArchive [data1, data2]
> <3072 bytes> : Bytes.Bytes
Try
import Tar exposing(..) extractArchive testArchive
to test this function
A small tar archive for testing purposes
Example
import Tar exposing(defaultMetadata)
metaData_ =
defaultMetadata
metaData1 =
{ metaData_ | filename = "a.txt" }
content1 =
"One two three\n"
metaData2
{ metaData_ | filename = "c.binary" }
content2 =
Hex.toBytes "1234" |> Maybe.withDefault (encode (Bytes.Encode.unsignedInt8 0))
Tar.encodeFiles
[ ( metaData1, StringData content1 )
, ( metaData2, BinaryData content2 )
]
|> Bytes.Encode.encode
Note: `Hex` is found in `jxxcarlson/hex` Example:
> encodeTextFile defaultMetadata "Test!" |> encode
> <1024 bytes> : Bytes.Bytes
Example
encodeFiles [(defaultMetadata, "This is a test"), (defaultMetadata, "Lah di dah do day!")] |> Bytes.Encode.encode == <2594 bytes> : Bytes
defaultMetadata is a dummy MetaData value that you modify to suit your needs. It contains a lot of boilerplates
Example
metaData= { defaultMetadata | filename = "Test.txt" }
See the definition of MetaData 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