Documentation ¶
Overview ¶
Package zipcmt is a viewer and an extractor of zip archive comments.
Index ¶
- Variables
- func Read(name string, raw bool) (string, error)
- type Config
- func (c *Config) Clean() error
- func (c *Config) Error(err error)
- func (i *Config) LogName() string
- func (c *Config) Separator(name string) string
- func (i *Config) SetLog()
- func (i *Config) SetTest()
- func (i *Config) SetTimer()
- func (c Config) Status() string
- func (i *Config) Timer() time.Duration
- func (c *Config) WalkDir(root string) error
- func (c *Config) WalkDirs()
- func (c *Config) WriteLog(s string)
Examples ¶
Constants ¶
This section is empty.
Variables ¶
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 ¶
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 ¶
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) LogName ¶
func (i *Config) LogName() string
SetLog returns the full path to the log 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) SetTimer ¶
func (i *Config) SetTimer()
SetTimer initializes a timer for process time.
func (Config) Status ¶
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) WalkDir ¶
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