cachefs

package
v0.0.0-...-986f64f Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2023 License: BSD-3-Clause Imports: 7 Imported by: 0

Documentation

Overview

cachefs实现了缓存文件系统

缓存文件系统用于在http.FileSystem默认实现需要优化 缓存文件系统在Open和Read时如果没有修改,不会进行系统调用,而是使用缓存

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Buf

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

循环缓存 当到末尾是不会返回io.EoF,会下次从头读取

func NewBuf

func NewBuf(buf []byte) *Buf

创建循环缓存

func (*Buf) Empty

func (buf *Buf) Empty() bool

判断缓存是否到末尾

func (*Buf) Read

func (buf *Buf) Read(p []byte) (n int, err error)

实现io.Reader接口,读取缓存内容 当到末尾是不会返回io.EoF,会下次从头读取

func (*Buf) Seek

func (buf *Buf) Seek(offset int64, whence int) (int64, error)

实现io.Seeker接口

type CacheFs

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

缓存文件系统 在Open和Read时如果没有修改,不会进行系统调用,而是使用缓存

func NewCacheFs

func NewCacheFs(name string) (fs *CacheFs, err error)

创建缓存文件系统

func (*CacheFs) Close

func (fs *CacheFs) Close() error

关闭 为了能配合http.FileServer,永远返回nil

func (*CacheFs) Read

func (fs *CacheFs) Read(p []byte) (n int, err error)

实现io.Reader接口,如果没有修改,将返回缓存内容

func (*CacheFs) Readdir

func (fs *CacheFs) Readdir(count int) ([]fs.FileInfo, error)

返回目录信息 目前返回nil,nil

func (*CacheFs) Seek

func (fs *CacheFs) Seek(offset int64, whence int) (int64, error)

实现io.Seeker接口,如果没有修改,将移动缓存内容偏移量

func (*CacheFs) Stat

func (fs *CacheFs) Stat() (fs.FileInfo, error)

返回文件信息

type HttpCacheFs

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

Http缓存文件系统

Example
http.Handle("/", http.FileServer(NewHttpCacheFs(`E:\前端\html`)))
Output:

func NewHttpCacheFs

func NewHttpCacheFs(path string) *HttpCacheFs

创建NewHttpCacheFs path 是相对的路径 相当于http.Dir

func (*HttpCacheFs) Open

func (fs *HttpCacheFs) Open(name string) (http.File, error)

Open实现http.FileSystem接口

Jump to

Keyboard shortcuts

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