zipasfolder

package
v1.0.13 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 11, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

README

zipasfolder

zipasfolder is a wrapper that treats ZIP files within a base filesystem as if they were folders.

Features

  • Transparent Expansion: When navigating a path, if a .zip file is encountered, the wrapper treats it as a directory.
  • Dynamic Mounting: Automatically "mounts" ZIP files when accessed.
  • Cache Management: Uses a cache for opened ZIP files to improve performance.
  • Read/Write Support: If the underlying filesystem and ZIP implementation support it, writes can be performed directly into ZIP files within the folder structure.

Example

Given a file system with data/archive.zip containing file.txt. With zipasfolder, you can access it as: data/archive.zip/file.txt.

Usage

import (
	"github.com/je4/filesystem/v3/pkg/zipasfolder"
)

// Wrap an existing filesystem
fsys, err := zipasfolder.NewFS(baseFS, 10, time.Minute, false, logger)
if err != nil {
	// handle error
}

// Access a file inside a ZIP
f, err := fsys.Open("path/to/myarchive.zip/content.txt")

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewFS

func NewFS(baseFS fs.FS, cacheSize int, timeout time.Duration, readOnly bool, logger zLogger.ZLogger) (*zipAsFolderFS, error)

NewFS creates a new zipAsFolderFS which handles zipfiles like folders which are read-only it implements readwritefs.ReadWriteFS, fs.ReadDirFS, fs.ReadFileFS, basefs.CloserFS

func NewZipFSCloser

func NewZipFSCloser(zipFile fs.File, filename string, logger zLogger.ZLogger) (fs.FS, error)

NewZipFSCloser creates a new zipFSCloser which wraps a zip filesystem and the underlying zip file. It ensures the zip file is closed when the filesystem's reference count reaches zero and Close is called.

Types

type IsClosedFS

type IsClosedFS interface {
	IsClosed() bool
}

IsClosedFS is an interface for filesystems that can report their closed state.

type IsRefCountFS

type IsRefCountFS interface {
	fs.FS
	IncRef()
	DecRef()
	RefCount() int32
}

IsRefCountFS defines an interface for filesystems with reference counting.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL