tarfs

package
v2.0.24 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

// tarfs 包实现了 tar 档案的只读内存表示

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type File

type File struct {
	// contains filtered or unexported fields
}

File 代表 tar 文件系统中的文件结构

func (*File) Close

func (f *File) Close() error

Close 关闭文件 返回值:

  • error: 错误信息

func (*File) Name

func (f *File) Name() string

Name 返回文件名 返回值:

  • string: 文件名

func (*File) Read

func (f *File) Read(p []byte) (n int, err error)

Read 从文件中读取数据到 p 中 参数:

  • p: []byte 读取的数据存储到 p 中

返回值:

  • n: int 读取的字节数
  • err: 错误信息

func (*File) ReadAt

func (f *File) ReadAt(p []byte, off int64) (n int, err error)

ReadAt 从文件的特定偏移量处读取数据到 p 中 参数:

  • p: []byte 读取的数据存储到 p 中
  • off: int64 偏移量

返回值:

  • n: int 读取的字节数
  • err: 错误信息

func (*File) Readdir

func (f *File) Readdir(count int) ([]os.FileInfo, error)

Readdir 读取目录内容 参数:

  • count: int 读取的文件数量

返回值:

  • []os.FileInfo: 文件信息列表
  • error: 错误信息

func (*File) Readdirnames

func (f *File) Readdirnames(n int) ([]string, error)

Readdirnames 读取目录内容并返回文件名列表 参数:

  • n: int 读取的文件数量

返回值:

  • []string: 文件名列表
  • error: 错误信息

func (*File) Seek

func (f *File) Seek(offset int64, whence int) (int64, error)

Seek 移动文件的读取指针到指定位置 参数:

  • offset: int64 偏移量
  • whence: int 偏移的起始位置

返回值:

  • int64: 新的偏移位置
  • error: 错误信息

func (*File) Stat

func (f *File) Stat() (os.FileInfo, error)

Stat 返回文件的文件信息 返回值:

  • os.FileInfo: 文件信息
  • error: 错误信息

func (*File) Sync

func (f *File) Sync() error

Sync 将文件的更改同步到存储设备 返回值:

  • error: 错误信息

func (*File) Truncate

func (f *File) Truncate(size int64) error

Truncate 将文件截断到指定大小 参数:

  • size: int64 文件大小

返回值:

  • error: 错误信息

func (*File) Write

func (f *File) Write(p []byte) (n int, err error)

Write 向文件中写入数据 参数:

  • p: []byte 写入的数据

返回值:

  • n: int 写入的字节数
  • err: 错误信息

func (*File) WriteAt

func (f *File) WriteAt(p []byte, off int64) (n int, err error)

WriteAt 从文件的特定偏移量处写入数据 参数:

  • p: []byte 写入的数据
  • off: int64 偏移量

返回值:

  • n: int 写入的字节数
  • err: 错误信息

func (*File) WriteString

func (f *File) WriteString(s string) (ret int, err error)

WriteString 向文件中写入字符串 参数:

  • s: string 写入的字符串

返回值:

  • int: 写入的字节数
  • error: 错误信息

type Fs

type Fs struct {
	// contains filtered or unexported fields
}

Fs 代表一个只读的内存中的 tar 文件系统

func New

func New(t *tar.Reader) *Fs

New 创建一个新的 Fs 实例 参数:

  • t: *tar.Reader tar 文件读取器

返回值:

  • *Fs: 返回新创建的文件系统实例

func (*Fs) Chmod

func (fs *Fs) Chmod(name string, mode os.FileMode) error

Chmod 更改文件权限(只读文件系统,返回错误) 参数:

  • name: string 文件路径
  • mode: os.FileMode 文件权限

返回值:

  • error: 错误信息

func (*Fs) Chown

func (fs *Fs) Chown(name string, uid, gid int) error

Chown 更改文件所有者(只读文件系统,返回错误) 参数:

  • name: string 文件路径
  • uid: int 用户ID
  • gid: int 组ID

返回值:

  • error: 错误信息

func (*Fs) Chtimes

func (fs *Fs) Chtimes(name string, atime time.Time, mtime time.Time) error

Chtimes 更改文件时间(只读文件系统,返回错误) 参数:

  • name: string 文件路径
  • atime: time.Time 访问时间
  • mtime: time.Time 修改时间

返回值:

  • error: 错误信息

func (*Fs) Create

func (fs *Fs) Create(name string) (afero.File, error)

Create 创建新文件(只读文件系统,返回错误) 参数:

  • name: string 文件路径

返回值:

  • afero.File: 创建的文件
  • error: 错误信息

func (*Fs) Mkdir

func (fs *Fs) Mkdir(name string, perm os.FileMode) error

Mkdir 创建目录(只读文件系统,返回错误) 参数:

  • name: string 目录路径
  • perm: os.FileMode 目录权限

返回值:

  • error: 错误信息

func (*Fs) MkdirAll

func (fs *Fs) MkdirAll(path string, perm os.FileMode) error

MkdirAll 创建所有目录(只读文件系统,返回错误) 参数:

  • path: string 目录路径
  • perm: os.FileMode 目录权限

返回值:

  • error: 错误信息

func (*Fs) Name

func (fs *Fs) Name() string

Name 返回文件系统名称 返回值:

  • string: 文件系统名称

func (*Fs) Open

func (fs *Fs) Open(name string) (afero.File, error)

Open 打开指定路径的文件 参数:

  • name: string 文件路径

返回值:

  • afero.File: 打开的文件
  • error: 错误信息

func (*Fs) OpenFile

func (fs *Fs) OpenFile(name string, flag int, perm os.FileMode) (afero.File, error)

OpenFile 打开文件(只读模式) 参数:

  • name: string 文件路径
  • flag: int 打开文件的标志
  • perm: os.FileMode 文件权限

返回值:

  • afero.File: 打开的文件
  • error: 错误信息

func (*Fs) Remove

func (fs *Fs) Remove(name string) error

Remove 删除文件(只读文件系统,返回错误) 参数:

  • name: string 文件路径

返回值:

  • error: 错误信息

func (*Fs) RemoveAll

func (fs *Fs) RemoveAll(path string) error

RemoveAll 删除所有文件(只读文件系统,返回错误) 参数:

  • path: string 路径

返回值:

  • error: 错误信息

func (*Fs) Rename

func (fs *Fs) Rename(oldname string, newname string) error

Rename 重命名文件(只读文件系统,返回错误) 参数:

  • oldname: string 旧文件名
  • newname: string 新文件名

返回值:

  • error: 错误信息

func (*Fs) Stat

func (fs *Fs) Stat(name string) (os.FileInfo, error)

Stat 返回文件信息 参数:

  • name: string 文件路径

返回值:

  • os.FileInfo: 文件信息
  • error: 错误信息

Jump to

Keyboard shortcuts

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