zipcmt

package
v1.4.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 9, 2024 License: LGPL-3.0 Imports: 20 Imported by: 0

Documentation

Overview

Package zipcmt is a viewer and an extractor of zip archive comments.

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	ErrFlag     = errors.New("this option is used after a directory, it must be placed before any directories are listed")
	ErrDirExist = errors.New("directory does not exist")
	ErrIsFile   = errors.New("directory is a file")
	ErrMissing  = errors.New("directory cannot be found")
	ErrPath     = errors.New("directory path cannot be found or points to a file")
	ErrPerm     = errors.New("directory access is blocked due to its permissions")
	ErrRead     = errors.New("skip named zip file due to read error")
	ErrValid    = errors.New("the operating system reports this directory is invalid")
)

Functions

func Read

func Read(name string, raw bool) (string, error)

Read the named zip file and return the zip comment. The Raw config will return the comment in its original legacy encoding. Otherwise the comment is returned as Unicode text.

Example
package main

import (
	"fmt"
	"log"
	"os"

	zipcmt "github.com/bengarrett/zipcmt/pkg"
)

func main() {
	s, err := zipcmt.Read("../test/test-with-comment.zip", false)
	if err != nil {
		log.Fatalln(err)
	}
	fmt.Fprint(os.Stdout, s)
}
Output:

This is an example test comment for zipcmmt.

Types

type Config

type Config struct {
	Dirs      []string // Dirs are the directory paths to walk.
	SaveName  string   // SaveName is an optional directory path to save any found comments as uniquely named text files.
	Dupes     bool     // Dupes shows all comments, including duplicates found in multiple zips.
	Export    bool     // Export the comments as text files stored alongside the source zip files.
	Log       bool     // Log creates a logfile for debugging.
	Overwrite bool     // Overwrite any previously exported comment text files.
	// Now ignores the zip files last modification date, which is otherwise applied to the comment text file.
	Now    bool
	NoWalk bool // NoWalk ignores all subdirectories while scanning for zip archives.
	Raw    bool // Raw uses the original comment text encoding (CP437, ISO-8859...) instead of Unicode.
	Print  bool // Print found comments to stdout.
	Quiet  bool // Quiet suppresses the scan activity feedback to stdout.
	Zips   int  // Zips is the number of zip files scanned.
	Cmmts  int  // Cmmts are the number of zip comments found.
	// contains filtered or unexported fields
}

Config zipcmt to walk one or more directories.

Example
package main

import (
	"fmt"
	"os"

	zipcmt "github.com/bengarrett/zipcmt/pkg"
)

func main() { //nolint: testableexamples
	// print all comments found in the test directory
	example := []string{"../test"}
	a := zipcmt.Config{
		Dirs:  example,
		Dupes: true,
		Print: true,
	}
	a.WalkDirs()
	if s := a.Status(); s != "" {
		fmt.Fprintln(os.Stdout, s)
	}

	// quietly scan and save only the unique comments as text files in the home directory
	const homeDir = "~"
	b := zipcmt.Config{
		Dirs:     example,
		SaveName: homeDir,
		Quiet:    true,
	}
	b.WalkDirs()
	if s := b.Status(); s != "" {
		fmt.Fprintln(os.Stdout, s)
	}

	// quietly scan and count the unique comments
	c := zipcmt.Config{
		Dirs:  example,
		Quiet: true,
	}
	c.WalkDirs()
	fmt.Fprintf(os.Stdout, "Scanned %d zip archives and found %d unique comments\n", c.Zips, c.Cmmts)
}
Output:

func (*Config) Clean

func (c *Config) Clean() error

Clean the syntax and check the usability of the SaveName directory path.

Example
package main

import (
	"fmt"
	"log"
	"os"

	zipcmt "github.com/bengarrett/zipcmt/pkg"
)

func main() {
	c := zipcmt.Config{
		SaveName: "..//test///.",
	}
	if err := c.Clean(); err != nil {
		log.Fatalln(err)
	}
	fmt.Fprint(os.Stdout, c.SaveName)
}
Output:

../test

func (*Config) Error

func (c *Config) Error(err error)

Error saves the error to either a new or append an existing log file.

func (*Config) LogName

func (i *Config) LogName() string

SetLog returns the full path to the log file.

func (*Config) Separator

func (c *Config) Separator(name string) string

Separator prints and stylises the named file.

func (*Config) SetLog

func (i *Config) SetLog()

SetLog sets the full path to a new log file with a name based on the current date and time.

func (*Config) SetTest

func (i *Config) SetTest()

SetTest toggles the unit test mode flag.

func (*Config) SetTimer

func (i *Config) SetTimer()

SetTimer initializes a timer for process time.

func (Config) Status

func (c Config) Status() string

Status summarizes the zip files scan.

Example
package main

import (
	"fmt"
	"log"
	"os"

	zipcmt "github.com/bengarrett/zipcmt/pkg"
)

func main() {
	c := zipcmt.Config{}
	c.SetTest()
	if err := c.WalkDir("../test"); err != nil {
		log.Panicln(err)
	}
	fmt.Fprint(os.Stdout, c.Status())

	c = zipcmt.Config{
		Dupes: true,
	}
	c.SetTest()
	if err := c.WalkDir("../test"); err != nil {
		log.Panicln(err)
	}
	fmt.Fprint(os.Stdout, c.Status())
}
Output:

Scanned 4 zip archives and found 1 unique comment
Scanned 4 zip archives and found 2 comments

func (*Config) Timer

func (i *Config) Timer() time.Duration

Timer returns the time since the SetTimer was triggered.

func (*Config) WalkDir

func (c *Config) WalkDir(root string) error

WalkDir walks the root directory for zip archives and to extract any found comments.

Example
package main

import (
	"log"

	zipcmt "github.com/bengarrett/zipcmt/pkg"
)

func main() {
	c := zipcmt.Config{
		Print: true,
		Dupes: true,
	}
	if err := c.WalkDir("../test"); err != nil {
		log.Panicln(err)
	}
}
Output:

── ../test/subdir/test-with-comment.zip ─┐
   This is an example test comment for zipcmmt.�[0m

 ── ../test/test-with-comment.zip ────────┐
   This is an example test comment for zipcmmt.�[0m

func (*Config) WalkDirs

func (c *Config) WalkDirs()

WalkDirs walks the directories provided by the Arg slice for zip archives to extract any found comments.

func (*Config) WriteLog

func (c *Config) WriteLog(s string)

WriteLog saves the string to an appended or new log file.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL