jxxcarlson/elm-tar/3.0.9

NOTE: the latest version is 4.0.0

Tar

Use

encodeMetaData

   createArchive : List ( MetaData, Data ) -> Bytes

to 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 testArchive

For more details, see the README. See also the demo app ./examples/Main.elm

type Data
= StringData String
| BinaryData Bytes

Use StringData String for text data, BinaryData Bytes for binary data, e.g., StringData "This is a test" or BinaryData someBytes

type alias MetaData =
{ filename : String
, mode : Mode
, ownerID : Int
, groupID : Int
, fileSize : Int
, lastModificationTime : Int
, linkIndicator : Link
, linkedFileName : String
, userName : String
, groupName : String
, fileNamePrefix : String
}

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.

createArchive : List ( MetaData, Data ) -> Bytes
 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

extractArchive : Bytes -> List ( MetaData, Data )

Try

import Tar exposing(..) extractArchive testArchive

to test this function

testArchive : Bytes

A small tar archive for testing purposes

encodeFiles : List ( MetaData, Data ) -> Encoder
  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`
encodeTextFile : MetaData -> String -> Encoder
 Example:

> encodeTextFile defaultMetadata "Test!" |> encode
> <1024 bytes> : Bytes.Bytes

encodeTextFiles : List ( MetaData, String ) -> Encoder

Example

encodeFiles [(defaultMetadata, "This is a test"), (defaultMetadata, "Lah di dah do day!")] |> Bytes.Encode.encode == <2594 bytes> : Bytes

defaultMetadata : MetaData

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.