Skip to content

Commit 94134c1

Browse files
committed
feat: 优化zip爆破格式 & buffer 配置
1 parent 4d4afd9 commit 94134c1

8 files changed

Lines changed: 982 additions & 50 deletions

File tree

README.md

Lines changed: 84 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ cover: https://pan.weidows.tech/d/local/blog/1d36e9d50555af6fca23e5fd36246cf5490
2222
* @Author: Weidows
2323
* @LastEditors: Weidows
2424
* @Date: 2022-08-30 14:51:11
25-
* @LastEditTime: 2026-02-26 15:57:17
25+
* @LastEditTime: 2026-03-03 10:59:18
2626
* @FilePath: \wutils\README.md
2727
* @Description:
2828
* @:
@@ -58,7 +58,7 @@ cover: https://pan.weidows.tech/d/local/blog/1d36e9d50555af6fca23e5fd36246cf5490
5858
{% pullquote mindmap mindmap-sm %}
5959

6060
- [Docs-wutils](#docs-wutils)
61-
- [install](#install)
61+
- [install](#install)
6262
- [Cmd](#cmd)
6363
- [wutils](#wutils)
6464
- [parallel](#parallel)
@@ -74,6 +74,12 @@ cover: https://pan.weidows.tech/d/local/blog/1d36e9d50555af6fca23e5fd36246cf5490
7474
- [usage](#usage)
7575
- [example](#example)
7676
- [gmm](#gmm)
77+
- [buffer](#buffer)
78+
- [功能特性](#功能特性)
79+
- [用法](#用法)
80+
- [选项](#选项)
81+
- [配置文件](#配置文件)
82+
- [注意事项](#注意事项)
7783
- [Pkg](#pkg)
7884
- [zip](#zip-1)
7985
- [Utils](#utils)
@@ -83,7 +89,7 @@ cover: https://pan.weidows.tech/d/local/blog/1d36e9d50555af6fca23e5fd36246cf5490
8389

8490
<a>![分割线](https://pan.weidows.tech/d/local/img/divider.png)</a>
8591

86-
### install
92+
## install
8793

8894
```shell
8995
go install github.com/Weidows/wutils/cmd/wutils@master
@@ -106,12 +112,7 @@ https://github.com/Weidows/wutils/releases
106112

107113
### wutils
108114

109-
> `CPU`: <0.1% at most time. \
110-
> `RAM`: <10MB, very tiny.
111-
112115
- [x] 运行时配置热更新
113-
- [ ] break change: Rename from 'keep-runner' to 'wutils'
114-
- then some integrations and transfers will be gradully added.
115116

116117
```console
117118
╰─ 👉wutils
@@ -138,6 +139,7 @@ COMMANDS:
138139
把指定窗口设置opacity, 使其透明化 (same as BLend)
139140
zip some actions to operate zip/7z files
140141
media some actions to operate image or video files
142+
buffer Buffer filesystem - 基于 Dokan 的 IO 缓冲虚拟文件系统
141143
help, h Shows a list of commands or help for one command
142144

143145
GLOBAL OPTIONS:
@@ -188,12 +190,6 @@ wutils 部分子程序设计为根据 [配置文件](https://github.com/Weidows/
188190

189191
---
190192

191-
#### dsg-Disk_sleep_guard
192-
193-
参上介绍的
194-
195-
---
196-
197193
#### diff
198194

199195
自然, 可以通过 Git 和一些类似的工具实现 '行-差异' 的做法, 但是它们并不能输出, 作为差集
@@ -219,15 +215,19 @@ onlyA2
219215

220216
简而易懂, 破解压缩包
221217

222-
- 把名为 `password.txt` 的字典文件放在命令行所在目录
218+
- 自动在 `~/.config/wutils/password-dict.txt` 创建默认密码字典
223219
- 使用协程高速处理
224220
- `>=1000 test/s`
225221
- `~50%` CPU usage
226222
- `nMB ~ nGB` RAM usage
227223
- supporting
228-
- .7z
229224
- .zip
225+
- .7z
226+
- .rar
227+
- .tar.gz
228+
- .tar.bz2
230229
- 分卷文件 (.zip, .z01, .z02 ....)
230+
- 分卷 7z 文件 (.7z.001, .7z.002 ...)
231231

232232
---
233233

@@ -314,6 +314,74 @@ Golang package Mirror Manager
314314
- [x] 结果排序
315315
- [x] 协程加速
316316

317+
---
318+
319+
#### buffer
320+
321+
Buffer filesystem - 基于 Dokan 的 IO 缓冲虚拟文件系统
322+
323+
用于减少 HDD IOPS,对小文件随机读写场景特别有效。
324+
325+
##### 功能特性
326+
327+
- 基于 Dokan (Windows FUSE) 的透明缓冲
328+
- 写缓冲(write-behind):减少写操作次数
329+
- 读缓冲(LRU + read-ahead):热点数据缓存和预取
330+
- 可配置的缓冲策略:monitoring, defrag, download, migration, balanced
331+
- 支持配置文件管理和热更新
332+
333+
##### 用法
334+
335+
```bash
336+
# 挂载缓冲盘 X:,指向 D:/data
337+
wutils buffer mount X: --source D:/data
338+
339+
# 使用自定义内存限制(100MB)
340+
wutils buffer mount X: --source D:/data --memory-limit 104857600
341+
342+
# 使用自定义刷新间隔(30秒)
343+
wutils buffer mount X: --source D:/data --flush-interval 30
344+
345+
# 查看状态
346+
wutils buffer status
347+
348+
# 卸载缓冲盘
349+
wutils buffer unmount
350+
```
351+
352+
##### 选项
353+
354+
- `-s, --source` (必需): 源路径,需要缓冲的目录
355+
- `--memory-limit`: 内存限制,单位字节(默认: 67108864,64MB)
356+
- `--flush-interval`: 刷新间隔,单位秒(默认: 10)
357+
- `--strategy`: 缓冲策略
358+
- `monitoring`: 监控模式,低延迟
359+
- `defrag`: 碎片整理模式,大批量写
360+
- `download`: 下载模式,顺序写
361+
- `migration`: 迁移模式,批量读写
362+
- `balanced`: 平衡模式(默认)
363+
- `--enable-read-cache`: 启用读缓存(默认: false)
364+
- `--enable-write-buffer`: 启用写缓冲(默认: true)
365+
366+
##### 配置文件
367+
368+
`~/.config/wutils/app.yml` 中配置:
369+
370+
```yaml
371+
cmd:
372+
buffer:
373+
enable: false
374+
memory_limit: 67108864 # 64MB
375+
flush_interval: 10 # 10秒
376+
strategy: balanced # 策略
377+
```
378+
379+
##### 注意事项
380+
381+
- 需要安装 Dokan 驱动(https://github.com/dokan-dev/dokany)
382+
- 仅支持 Windows 平台
383+
- 建议配合 SSD 使用以获得最佳性能
384+
317385
<a>![分割线](https://pan.weidows.tech/d/local/img/divider.png)</a>
318386
319387
## Pkg

cmd/wutils/buffer/buffer.go

Lines changed: 57 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package buffer
22

33
import (
4+
"errors"
5+
"fmt"
46
"io"
57
"io/fs"
68
"os"
@@ -12,6 +14,15 @@ import (
1214
"github.com/binzume/dkango"
1315
)
1416

17+
// 错误定义
18+
var (
19+
ErrSourcePathNotExist = errors.New("源路径不存在或无法访问")
20+
ErrSourcePathNotDir = errors.New("源路径不是有效的目录")
21+
ErrMountPointInvalid = errors.New("挂载点无效")
22+
ErrMountFailed = errors.New("挂载失败")
23+
ErrAlreadyMounted = errors.New("已经存在挂载实例,请先卸载")
24+
)
25+
1526
type BufferConfig struct {
1627
SourcePath string
1728
MemoryLimit int64
@@ -27,7 +38,14 @@ type BufferFS struct {
2738
readCache *cache.LRU
2839
}
2940

30-
func NewBufferFS(config *BufferConfig) *BufferFS {
41+
func NewBufferFS(config *BufferConfig) (*BufferFS, error) {
42+
if config.SourcePath == "" {
43+
config.SourcePath = "."
44+
}
45+
if err := validateSourcePath(config.SourcePath); err != nil {
46+
return nil, err
47+
}
48+
3149
fs := &BufferFS{config: config}
3250
if config.EnableWriteBuffer {
3351
strategy := bufioutil.GetPresetStrategy(bufioutil.UseCase(config.Strategy))
@@ -39,10 +57,21 @@ func NewBufferFS(config *BufferConfig) *BufferFS {
3957
if config.EnableReadCache {
4058
fs.readCache = cache.NewLRU(config.MemoryLimit)
4159
}
42-
if config.SourcePath == "" {
43-
config.SourcePath = "."
60+
return fs, nil
61+
}
62+
63+
func validateSourcePath(sourcePath string) error {
64+
info, err := os.Stat(sourcePath)
65+
if err != nil {
66+
if os.IsNotExist(err) {
67+
return fmt.Errorf("%w: %s", ErrSourcePathNotExist, sourcePath)
68+
}
69+
return fmt.Errorf("%w: %s", ErrSourcePathNotExist, err.Error())
4470
}
45-
return fs
71+
if !info.IsDir() {
72+
return fmt.Errorf("%w: %s", ErrSourcePathNotDir, sourcePath)
73+
}
74+
return nil
4675
}
4776

4877
func (b *BufferFS) Open(name string) (fs.File, error) {
@@ -63,7 +92,17 @@ func (b *BufferFS) OpenWriter(name string, flag int) (io.WriteCloser, error) {
6392
if !fs.ValidPath(name) {
6493
return nil, &fs.PathError{Op: "open", Path: name, Err: fs.ErrInvalid}
6594
}
66-
return os.OpenFile(path.Join(b.config.SourcePath, name), flag, fs.ModePerm)
95+
f, err := os.OpenFile(path.Join(b.config.SourcePath, name), flag, 0644)
96+
if err != nil {
97+
if os.IsPermission(err) {
98+
return nil, fmt.Errorf("文件写入失败,权限不足: %s, 错误: %w", name, err)
99+
}
100+
if os.IsNotExist(err) {
101+
return nil, fmt.Errorf("文件写入失败,父目录不存在: %s, 错误: %w", name, err)
102+
}
103+
return nil, fmt.Errorf("文件写入失败: %s, 错误: %w", name, err)
104+
}
105+
return f, nil
67106
}
68107

69108
func (b *BufferFS) Remove(name string) error {
@@ -97,10 +136,21 @@ func (b *BufferFS) Truncate(name string, size int64) error {
97136
var mountInstance interface{ Close() error }
98137

99138
func Mount(drive string, config *BufferConfig) error {
100-
fs := NewBufferFS(config)
139+
if drive == "" {
140+
return fmt.Errorf("%w: 挂载点不能为空", ErrMountPointInvalid)
141+
}
142+
if mountInstance != nil {
143+
return fmt.Errorf("%w", ErrAlreadyMounted)
144+
}
145+
146+
fs, err := NewBufferFS(config)
147+
if err != nil {
148+
return fmt.Errorf("初始化BufferFS失败: %w", err)
149+
}
150+
101151
mount, err := dkango.MountFS(drive, fs, nil)
102152
if err != nil {
103-
return err
153+
return fmt.Errorf("%w: %v", ErrMountFailed, err)
104154
}
105155
mountInstance = mount
106156
return nil

0 commit comments

Comments
 (0)