Giter Club home page Giter Club logo

sevenzip-go's Introduction

sevenzip-go

Build Status GoDoc MIT licensed No Maintenance Intended

Bindings to use 7-zip as a library from golang.

Structure

sevenzip-go needs two dynamic libraries to operate, and it expects them to be in the executable's folder.

For example

  • On Windows, you'll need foobar.exe, c7zip.dll, and 7z.dll in the same directory
  • On Linux, you'll need foobar, libc7zip.so, and 7z.so in the same directory
  • On macOS, you'll need foobar, libc7zip.dylib, and 7z.so in the same directory

Note: the 7-zip library is called 7z.so on macOS, that's not a typo.

If it can't find it, it'll print messages to stderr (and return an error).

Rationale

sevenzip-go was made primarily to serve as a decompression engine for https://github.com/itchio/butler

most of butler's functionality does not require 7-zip, and:

  • we want folks to be able to build butler easily, without having to build C/C++ projects manually
  • we want folks to be able to run their custom butler builds easily, without having to worry about missing dynamic libraries
  • we want to use 7z.dll from the official 7-zip builds (it is a notorious pain to build, as it requires MSVC 2010)

While the whole setup sounds crazy (especially considering the whole Go->cgo->C->C++->COM/C++ pipeline), it fits all those goals.

Caveats

Pay attention to the dynamic library requirement above:

Neither sevenzip-go nor lib7zip look for DLLs in the PATH or LD_LIBRARY_PATH or DYLD_LIBRARY_PATH, they only look in the executable's directory. This is on purpose, so we don't accidentally load an older version of 7-zip.

The library allocates memory via C functions, so you should make sure to call .Free() on the various objects you get from sevenzip-go.

Error handling is best-effort, but there's many moving pieces involved here. Some items of an archive may fail to extract, the errors can be retrieved with extractCallback.Errors() (which returns a slice of errors).

Example

The ./cmd/go7z package

Links

License

sevenzip-go is released under the MIT license, see the LICENSE file.

Other required components are distributed under the MPL 2.0, the LGPL 2.1, and other terms - see their own LICENSE or COPYING files.

sevenzip-go's People

Contributors

fasterthanlime avatar

Stargazers

鍕囧線鐩村墠KJ avatar Ranor avatar ik5 avatar  avatar Vanisper avatar  avatar  avatar Dmitry Ledentsov avatar Cl茅ment Boudereau avatar Kirill Trofimov avatar Johan Brostr枚m avatar  avatar  avatar Ziloka avatar  avatar  avatar Les d茅p么ts de Nicolugo avatar  avatar  avatar Luiz Ant么nio avatar Tools avatar Fagner Nunes Carvalho avatar Saint Wish avatar Thomas Chandler avatar Neo avatar RVU avatar Joshua Briefman avatar Shuhao_test avatar Paulo Pereira avatar jackie avatar Lennart Engelberg avatar  avatar  avatar  avatar

Watchers

James Cloos avatar jackie avatar  avatar  avatar

sevenzip-go's Issues

Example of opening file from archive

Hello,

I am interested in using this code for my project, but I am not too familiar with the 7z part of the code. I want to use this code to simply take the archive, Loop through the files and analyze them, without unzipping to the disk.

I am not 100% sure how to go about doing that with your library, and I am a bit in over my head.

looking at your code I have this:

func main() {
	//Initialize the lib
	lib, err := sz.NewLib()
	must(err)
	defer lib.free()

	//Get the file reference
	f, err :- os.Open("file.7z")
	must(err)
	
	//Get the file stats
	stats, err := f.Stat()
	must(err)
	
	//Open the 7z file
	is, err := sz.NewInStream(f, "7z", stats.Size())
	is.Stats - &sz.ReadStats{}
	a, err := lib.OpenArchive(is, true)
	must(err)
	
	//This is where my understanding gets a bit fuzzy...

After this it looks like the ecs struct above is used with the "GetStream" function, and I can see how the GetStream function extracts to a file, that makes sense. Here are my more specific questions...

  1. is GetStream called for each item? I think it is, but I want to be sure I understand this.
  2. if it is per item, what code would I have to write to simply open the file, so I can read it as a text or binary just like os.Open?

I would be happy to write up some examples like you have for the command line once I understand a very trivial example of opening a file found inside of the archive! Thank you for taking the time to read this!

Bundling the dynamic libraries in a GUI app on macos

sevenzip-go needs two dynamic libraries to operate, and it expects them to be in the executable's folder.

I am looking for a way to integrate this library into my GUI app. As far I know after bundling the app the dynamic libraries will reside inside the "Resources" directory of the app. Will it work?

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.