zipcmt

package
v1.3.10 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2022 License: LGPL-3.0 Imports: 18 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")
	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"

	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.Print(s)
}
Output:

This is an example test comment for zipcmmt.

Types

type Config

type Config struct {
	Dirs      []string
	SaveName  string
	Dupes     bool
	Export    bool
	Log       bool
	Overwrite bool
	Now       bool
	NoWalk    bool
	Raw       bool
	Print     bool
	Quiet     bool
	Zips      int
	Cmmts     int
	// contains filtered or unexported fields
}

func (*Config) Clean

func (c *Config) Clean() error

Clean the syntax of the target export directory path.

Example
package main

import (
	"fmt"
	"log"

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

func main() {
	c := zipcmt.Config{
		SaveName: "..//test///.",
	}
	if err := c.Clean(); err != nil {
		log.Fatalln(err)
	}
	fmt.Print(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"

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

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

	c = zipcmt.Config{
		Dupes: true,
	}
	c.SetTest()
	if err := c.WalkDir("../test"); err != nil {
		log.Panicln(err)
	}
	fmt.Print(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