Comments (12)
Yeah... this is what I have right now:
f, _ := os.Open("foo.zip")
s, _ := f.Stat()
i, _, _ := archiver.Identify(f.Name(), f)
a := &archiver.ArchiveFS{
Stream: io.NewSectionReader(f, 0, s.Size()),
Format: i.(archiver.Archival),
}
a.Sub(".")
So I guess I could reopen f after Indentify()? But still this is little cumbersome. It would be super nice if archiver.FileSystem()
could also take stream in addition to filename. Thanks!
from archiver.
@mholt I'm still new to go and some things seem unusual/unexpected, ha!
Any reason you can't make the Stream field an io.Reader (no pointer)?
Indeed, seems, that pointer type was another issue. I'll experiment more with it soon! Thank you for the hint!
What happened after that?
Seems, I've hit another issue, #371 may be. I can list the top-level dir of control.tar.gz
but unable to .Open()
files from there...
from archiver.
@mholt nothing fancy there, but, okay, I'll arrange it soon
from archiver.
You want ArchiveFS
-- simply specify the Stream
field instead of the Path
field.
Thanks for using archiver!
(If I've misunderstood your request, feel free to let me know.)
from archiver.
It worked, thank you! However it was pretty hard to figure out how to use this correctly. It was crashing on me until Format
was specified from Identify()
with a cast to archiver.Archival
. Identify returns io.Reader
to be used in further calls but I don't see an easy way to pass it directly to ArchiveFS
which requires SectionReader. For this I used io.NewSectionReader
from the opened file. But overall its little confusing. It could use an example. Thank you!
from archiver.
Oh... if you don't know the format ahead of time, I guess that can be a little tricky; because Identify() reads some of the bytes, so you have to use the new reader it returns. I didn't realize you had an unknown format.
Maybe we can add an exported API for calling FileSystem on a stream...
from archiver.
M'kay, I'll leave this open and give it some thought. I'd also accept a proposal to review for quicker turnaround!
from archiver.
Well, this is fantastic, thank you! But I have a more sophisticated case with which I'm, ahem, a bit stuck..
- I have an
.iso
file, which I turn intofs.FS
with (a tweaked version of) go-diskfs (after I've managed to mock diskfs/go-diskfs#169) - ... from which I get an
ar
file (debian package[1]) which I turn intofs.FS
witharchiver.ArchiveFS
(plus ar implementation ofarchiver.Archival
) - ...from which (I'd like to) have a
control.tar.gz
anddata.tar.xz
turned into correspondingfs.FS
(again, witharchiver.ArchiveFS
) and pick files from there - ...and serve all that with
http.FileServer(http.FS(myCrazyStackableFs))
ofnet/http
So, on each layer of abstraction I have an fs.File
, which is, unfortunately, not a io.ReaderAt
which is expected as an argument of io.NewSectionReader
As a wild guess, I've made a breaking experiment. I've changed ArchiveFS
to the following (which is, I'm quite sure, wrong, but, again, it's a wild guess 😅):
type ArchiveFS struct {
// set one of these
Path string // path to the archive file on disk, or...
Stream *io.Reader // ...stream from which to read archive
Format Archival // the archive format
Prefix string // optional subdirectory in which to root the fs
Context context.Context // optional
}
And surprisingly managed to reach up to point number 3 in my unusual journey, but not further, unfortunately.... Any hints would be appreciated!
The idea behind this is pretty simple: you navigate to a web resource which serves you a list of iso files from a directory on disk. You can dig into iso contents by clicking on corresponding name and navigate deeper and deeper, digging inside all known file types.
[1]: Debian binary package (a .deb
file) is actually an ar
archive, consisting of three files: control.tar.gz
- Debian-specific data, data.tar.xz
- actual package contents and debian-binary
- a text file. Compression formats may vary.
from archiver.
@aol-nnov Interesting -- thanks for chiming in.
Any reason you can't make the Stream field an io.Reader
(no pointer)? Pointers to interfaces are exceptionally unusual.
point number 3 in my unusual journey, but not further, unfortunately....
What happened after that?
from archiver.
@aol-nnov Thanks for working on this, sorry for the late reply.
Do you want to update your PR with the latest changes? Then maybe we can focus on #371...
from archiver.
Hey, @mholt !
Do you want to update your PR
I do not have any as yet! I think you have me confused with someone else :)
Do you want me to make a PR for Stream io.Reader
in ArchiveFS struct?
from archiver.
My bad, you're right -- I guess I'd be curious to see the patch, though -- no guarantees it'll be merged, but curious what it looks like!
from archiver.
Related Issues (20)
- Expose CompressionLevel for Zstd HOT 2
- Can not find extracted file anywhere HOT 1
- stuck on read/copy while extract rar file HOT 1
- v4 will decompress docx HOT 3
- 7z should have Archive method HOT 3
- Using rewindReader as a public type allows external access HOT 2
- Recursive decompression 7z does not work HOT 8
- go:embed via []byte stream or fs.File support HOT 3
- Fails to read file from archiver.FileSystem when archive is .tar.zst HOT 6
- How to provide dictionary for ZSTD encoder/decoder? HOT 4
- ArchiveAsync interface changes HOT 3
- File.Open given to the handler for Tar.Extract can't be used after the handler has returned HOT 5
- cannot archiver rar format HOT 2
- why '7z' not supported by Command HOT 2
- Unable to decrypt 7-ZIP file with password (err: breader.ReadByte: no data!) HOT 1
- Unable to decrypt 7-ZIP file with password (err: breader.ReadByte: no data!) HOT 1
- Is 7z supported by 4.0 Library? HOT 1
- RAR signature not found HOT 4
- If overwrite is enabled for unarchive, and the file being overwritten is a symlink, then it tries to follow the symlink, rather than replace it HOT 12
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from archiver.