forked from microsoft/hdfs-mount
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ZipFile.go
37 lines (32 loc) · 1.1 KB
/
ZipFile.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for details.
package main
import (
"archive/zip"
"bazil.org/fuse"
"bazil.org/fuse/fs"
"golang.org/x/net/context"
)
// Encapsulates state and operations for a virtual file inside zip archive on HDFS file system
type ZipFile struct {
Attrs Attrs
zipFile *zip.File
FileSystem *FileSystem
}
// Verify that *Dir implements necesary FUSE interfaces
var _ fs.Node = (*ZipFile)(nil)
var _ fs.NodeOpener = (*ZipFile)(nil)
// Responds on FUSE Attr request to retrieve file attributes
func (this *ZipFile) Attr(ctx context.Context, fuseAttr *fuse.Attr) error {
return this.Attrs.Attr(fuseAttr)
}
// Responds on FUSE Open request for a file inside zip archive
func (this *ZipFile) Open(ctx context.Context, req *fuse.OpenRequest, resp *fuse.OpenResponse) (fs.Handle, error) {
contentStream, err := this.zipFile.Open()
if err != nil {
return nil, err
}
// reporting to FUSE that the stream isn't seekable
resp.Flags |= fuse.OpenNonSeekable
return NewZipFileHandle(contentStream), nil
}