Git Product home page Git Product logo

archivex's Issues

Naming conventions

Can you please update Readme with the file naming conventions and its associated compression.

I noticed it in a pull request but didn't understand it.
In fact, I still can't work out the difference between the archive and compress packages.

AddAll keeps files it added open!

Hi all,

AddAll() does not close the files it added to the archive.
So the following use case is not implementable:

  1. archive directory
  2. remove directory (will fail cause all files still open)

my local fix in
func addAll(dir string, rootDir string, includeCurrentFolder bool, writerFunc ArchiveWriteFunc) error:

after line 336 i added

if file != nil { file.(*os.File).Close() }

getSubDir() path bug when dot is present

Thanks for the package! Seems like the quickest one so far :D

Just thought I'd mention that the strings.Replace in there is greedy, for example an npm package of node_modules/graph.ql/lib/index.js will have the root . replaced leading to graphql

Use of literal "/"

Sprinkled throughout your code, you use a literal "/" instead of, for example, os.PathSeparator, or using path.Join to combine things.

This leads to some oddities. For example, when using zip.AddAll("/usr/mydir", true), your package panics because I do not have a trailing slash on my directory name: it cannot find, for example, "/usr/mydirmysubdir".

The interface that your package exposes is significantly more user-friendly than trying to use the standard zip package directly, but it would be great if you could use path.Join and such, both for cross-platform support and to avoid oddities like requiring a trailing slash on my directory name.

Thanks!

Permission Clobbering

When archiving the application clobbers the permissions of the original file to 0666. This is suboptimal and is overly permissive. I'll write a patch soon.

Matching patterns and gz compression

In the check for compression the application only checks for the string "tar.gz", but "tgz", "tar.gzip", etc. are very common. I would suggest removing these string checks and add to the documentation to set the tar.Compressed = true flag.

AddAll with includeCurrentFolder=false has leading slashes on subdirectories in the archive

Given a simple zip creation setup like:

    zipFile := new(archivex.ZipFile)
    buf := new(bytes.Buffer)
    zipFile.Writer = zip.NewWriter(buf)
    zipFile.AddAll("/tmp/dir", false)
    zipFile.Close()

The AddAll specifies includeCurrentFolder=false. There's no issues when it's true.

The produced .zip gives me the following when I attempt to unzip it.

โžœ  unzip -t blah.zip
Archive:  blah.zip
    testing: a.xsd       OK
    testing: b.xsd              OK
    testing: /thing/                   OK
    testing: /thing/blank.htm          OK
    testing: /thing/easyxdm/           OK
    testing: /thing/easyxdm/MIT-license.txt   OK
    testing: /thing/index.htm          OK
    testing: /thing/js/                OK
    testing: /thing/js/API.js   OK
    testing: /thing/js/Utils.js        OK

The leading slashes should not be there, and could cause issues with some zip clients.

I've submitted PR #17 to address it.

Println in TarFile struct

Hi,

Why TarFile struct has so many fmt.Println?

I have a console application and every time I compress a file I see messages from TarFile on the terminal. It does not happen for ZipFile.

Cheers!

Query regarding logic

This is a great little library found it really useful. I was just reading the source and Im new to go I had a thought around these lines thought maybe worth mentioning.

https://github.com/jhoonb/archivex/blob/master/archivex.go#L53-L60

	if strings.HasSuffix(name, ".zip") != true {
		if strings.HasSuffix(name, ".tar.gz") == true {
			name = strings.Replace(name, ".tar.gz", ".zip", -1)
		} else {
			name = name + ".zip"
		}
	}
	z.Name = name

could it not be better written as

	if strings.HasSuffix(name, ".zip") == true {
		z.Name = name
	}

	if strings.HasSuffix(name, ".tar.gz") == true {
		z.Name = strings.Replace(name, ".tar.gz", ".zip", -1)
	}

	if z.Name == "" {
		z.Name = name + ".zip"
	}

the idea being that code with one level of indentation is easier to read. If you think that is an improvement Id be happy to do a PR else you can close my issue. Thanks again for the library works really well.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.