Skip to content

Commit

Permalink
Add usage examples
Browse files Browse the repository at this point in the history
  • Loading branch information
andyone committed Aug 13, 2023
1 parent f1c87f2 commit a3c7845
Show file tree
Hide file tree
Showing 13 changed files with 578 additions and 0 deletions.
46 changes: 46 additions & 0 deletions bz2/example_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package bz2

// ////////////////////////////////////////////////////////////////////////////////// //
// //
// Copyright (c) 2023 ESSENTIAL KAOS //
// Apache License, Version 2.0 <https://www.apache.org/licenses/LICENSE-2.0> //
// //
// ////////////////////////////////////////////////////////////////////////////////// //

import (
"fmt"
"os"
)

// ////////////////////////////////////////////////////////////////////////////////// //

func ExampleUnpack() {
file := "file.bz2"
err := Unpack(file, "/home/bob/data")

if err != nil {
fmt.Printf("Error: Can't unpack %s: %v\n", file, err)
return
}

fmt.Printf("File %s successfully unpacked!\n", file)
}

func ExampleRead() {
file := "file.bz2"
fd, err := os.OpenFile(file, os.O_RDONLY, 0)

if err != nil {
fmt.Printf("Error: Can't unpack %s: %v\n", file, err)
return
}

err = Read(fd, "/home/bob/data")

if err != nil {
fmt.Printf("Error: Can't unpack %s: %v\n", file, err)
return
}

fmt.Printf("File %s successfully unpacked!\n", file)
}
26 changes: 26 additions & 0 deletions example_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package npck

// ////////////////////////////////////////////////////////////////////////////////// //
// //
// Copyright (c) 2023 ESSENTIAL KAOS //
// Apache License, Version 2.0 <https://www.apache.org/licenses/LICENSE-2.0> //
// //
// ////////////////////////////////////////////////////////////////////////////////// //

import (
"fmt"
)

// ////////////////////////////////////////////////////////////////////////////////// //

func ExampleUnpack() {
file := "file.tzg"
err := Unpack(file, "/home/bob/data")

if err != nil {
fmt.Printf("Error: Can't unpack %s: %v\n", file, err)
return
}

fmt.Printf("File %s successfully unpacked!\n", file)
}
46 changes: 46 additions & 0 deletions gz/example_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package gz

// ////////////////////////////////////////////////////////////////////////////////// //
// //
// Copyright (c) 2023 ESSENTIAL KAOS //
// Apache License, Version 2.0 <https://www.apache.org/licenses/LICENSE-2.0> //
// //
// ////////////////////////////////////////////////////////////////////////////////// //

import (
"fmt"
"os"
)

// ////////////////////////////////////////////////////////////////////////////////// //

func ExampleUnpack() {
file := "file.gz"
err := Unpack(file, "/home/bob/data")

if err != nil {
fmt.Printf("Error: Can't unpack %s: %v\n", file, err)
return
}

fmt.Printf("File %s successfully unpacked!\n", file)
}

func ExampleRead() {
file := "file.gz"
fd, err := os.OpenFile(file, os.O_RDONLY, 0)

if err != nil {
fmt.Printf("Error: Can't unpack %s: %v\n", file, err)
return
}

err = Read(fd, "/home/bob/data")

if err != nil {
fmt.Printf("Error: Can't unpack %s: %v\n", file, err)
return
}

fmt.Printf("File %s successfully unpacked!\n", file)
}
46 changes: 46 additions & 0 deletions lz4/example_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package lz4

// ////////////////////////////////////////////////////////////////////////////////// //
// //
// Copyright (c) 2023 ESSENTIAL KAOS //
// Apache License, Version 2.0 <https://www.apache.org/licenses/LICENSE-2.0> //
// //
// ////////////////////////////////////////////////////////////////////////////////// //

import (
"fmt"
"os"
)

// ////////////////////////////////////////////////////////////////////////////////// //

func ExampleUnpack() {
file := "file.lz4"
err := Unpack(file, "/home/bob/data")

if err != nil {
fmt.Printf("Error: Can't unpack %s: %v\n", file, err)
return
}

fmt.Printf("File %s successfully unpacked!\n", file)
}

func ExampleRead() {
file := "file.lz4"
fd, err := os.OpenFile(file, os.O_RDONLY, 0)

if err != nil {
fmt.Printf("Error: Can't unpack %s: %v\n", file, err)
return
}

err = Read(fd, "/home/bob/data")

if err != nil {
fmt.Printf("Error: Can't unpack %s: %v\n", file, err)
return
}

fmt.Printf("File %s successfully unpacked!\n", file)
}
46 changes: 46 additions & 0 deletions tar/example_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package tar

// ////////////////////////////////////////////////////////////////////////////////// //
// //
// Copyright (c) 2023 ESSENTIAL KAOS //
// Apache License, Version 2.0 <https://www.apache.org/licenses/LICENSE-2.0> //
// //
// ////////////////////////////////////////////////////////////////////////////////// //

import (
"fmt"
"os"
)

// ////////////////////////////////////////////////////////////////////////////////// //

func ExampleUnpack() {
file := "file.tar"
err := Unpack(file, "/home/bob/data")

if err != nil {
fmt.Printf("Error: Can't unpack %s: %v\n", file, err)
return
}

fmt.Printf("File %s successfully unpacked!\n", file)
}

func ExampleRead() {
file := "file.tar"
fd, err := os.OpenFile(file, os.O_RDONLY, 0)

if err != nil {
fmt.Printf("Error: Can't unpack %s: %v\n", file, err)
return
}

err = Read(fd, "/home/bob/data")

if err != nil {
fmt.Printf("Error: Can't unpack %s: %v\n", file, err)
return
}

fmt.Printf("File %s successfully unpacked!\n", file)
}
46 changes: 46 additions & 0 deletions tbz2/example_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package tbz2

// ////////////////////////////////////////////////////////////////////////////////// //
// //
// Copyright (c) 2023 ESSENTIAL KAOS //
// Apache License, Version 2.0 <https://www.apache.org/licenses/LICENSE-2.0> //
// //
// ////////////////////////////////////////////////////////////////////////////////// //

import (
"fmt"
"os"
)

// ////////////////////////////////////////////////////////////////////////////////// //

func ExampleUnpack() {
file := "file.tbz2"
err := Unpack(file, "/home/bob/data")

if err != nil {
fmt.Printf("Error: Can't unpack %s: %v\n", file, err)
return
}

fmt.Printf("File %s successfully unpacked!\n", file)
}

func ExampleRead() {
file := "file.tbz2"
fd, err := os.OpenFile(file, os.O_RDONLY, 0)

if err != nil {
fmt.Printf("Error: Can't unpack %s: %v\n", file, err)
return
}

err = Read(fd, "/home/bob/data")

if err != nil {
fmt.Printf("Error: Can't unpack %s: %v\n", file, err)
return
}

fmt.Printf("File %s successfully unpacked!\n", file)
}
46 changes: 46 additions & 0 deletions tgz/example_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package tgz

// ////////////////////////////////////////////////////////////////////////////////// //
// //
// Copyright (c) 2023 ESSENTIAL KAOS //
// Apache License, Version 2.0 <https://www.apache.org/licenses/LICENSE-2.0> //
// //
// ////////////////////////////////////////////////////////////////////////////////// //

import (
"fmt"
"os"
)

// ////////////////////////////////////////////////////////////////////////////////// //

func ExampleUnpack() {
file := "file.tgz"
err := Unpack(file, "/home/bob/data")

if err != nil {
fmt.Printf("Error: Can't unpack %s: %v\n", file, err)
return
}

fmt.Printf("File %s successfully unpacked!\n", file)
}

func ExampleRead() {
file := "file.tgz"
fd, err := os.OpenFile(file, os.O_RDONLY, 0)

if err != nil {
fmt.Printf("Error: Can't unpack %s: %v\n", file, err)
return
}

err = Read(fd, "/home/bob/data")

if err != nil {
fmt.Printf("Error: Can't unpack %s: %v\n", file, err)
return
}

fmt.Printf("File %s successfully unpacked!\n", file)
}
46 changes: 46 additions & 0 deletions tlz4/example_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package tlz4

// ////////////////////////////////////////////////////////////////////////////////// //
// //
// Copyright (c) 2023 ESSENTIAL KAOS //
// Apache License, Version 2.0 <https://www.apache.org/licenses/LICENSE-2.0> //
// //
// ////////////////////////////////////////////////////////////////////////////////// //

import (
"fmt"
"os"
)

// ////////////////////////////////////////////////////////////////////////////////// //

func ExampleUnpack() {
file := "file.tlz4"
err := Unpack(file, "/home/bob/data")

if err != nil {
fmt.Printf("Error: Can't unpack %s: %v\n", file, err)
return
}

fmt.Printf("File %s successfully unpacked!\n", file)
}

func ExampleRead() {
file := "file.tlz4"
fd, err := os.OpenFile(file, os.O_RDONLY, 0)

if err != nil {
fmt.Printf("Error: Can't unpack %s: %v\n", file, err)
return
}

err = Read(fd, "/home/bob/data")

if err != nil {
fmt.Printf("Error: Can't unpack %s: %v\n", file, err)
return
}

fmt.Printf("File %s successfully unpacked!\n", file)
}
Loading

0 comments on commit a3c7845

Please sign in to comment.