jhoonb / archivex Goto Github PK
View Code? Open in Web Editor NEWarchivex is a golang package that archives folders (recursively) and files to zip and tar formats.
License: BSD 3-Clause "New" or "Revised" License
archivex is a golang package that archives folders (recursively) and files to zip and tar formats.
License: BSD 3-Clause "New" or "Revised" License
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.
Hi all,
AddAll() does not close the files it added to the archive.
So the following use case is not implementable:
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() }
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
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!
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.
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.
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.
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!
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.
Could archivex get an exclusion feature, like zip -x <pattern>
?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.