@casfa/storage-fs 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/README.md +0 -127
- package/README.zh-CN.md +0 -127
package/package.json
CHANGED
package/README.md
DELETED
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
# @casfa/storage-fs
|
|
2
|
-
|
|
3
|
-
File system storage provider for CAS.
|
|
4
|
-
|
|
5
|
-
## Installation
|
|
6
|
-
|
|
7
|
-
```bash
|
|
8
|
-
bun add @casfa/storage-fs
|
|
9
|
-
```
|
|
10
|
-
|
|
11
|
-
## Overview
|
|
12
|
-
|
|
13
|
-
A file system-backed storage provider for CAS (Content-Addressable Storage). Stores content in a sharded directory structure for efficient file system performance.
|
|
14
|
-
|
|
15
|
-
### Storage Structure
|
|
16
|
-
|
|
17
|
-
```
|
|
18
|
-
{basePath}/
|
|
19
|
-
├── ab/
|
|
20
|
-
│ └── cd/
|
|
21
|
-
│ └── abcd1234... (full hash)
|
|
22
|
-
├── ef/
|
|
23
|
-
│ └── 01/
|
|
24
|
-
│ └── ef012345...
|
|
25
|
-
└── ...
|
|
26
|
-
```
|
|
27
|
-
|
|
28
|
-
## Usage
|
|
29
|
-
|
|
30
|
-
### Basic Usage
|
|
31
|
-
|
|
32
|
-
```typescript
|
|
33
|
-
import { createFsStorage } from '@casfa/storage-fs';
|
|
34
|
-
|
|
35
|
-
const storage = createFsStorage({
|
|
36
|
-
basePath: '/var/cas/data',
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
// Store data
|
|
40
|
-
await storage.put('node:abcd1234...', data);
|
|
41
|
-
|
|
42
|
-
// Retrieve data
|
|
43
|
-
const data = await storage.get('node:abcd1234...');
|
|
44
|
-
|
|
45
|
-
// Check existence
|
|
46
|
-
const exists = await storage.has('node:abcd1234...');
|
|
47
|
-
|
|
48
|
-
// Delete
|
|
49
|
-
const deleted = await storage.delete('node:abcd1234...');
|
|
50
|
-
```
|
|
51
|
-
|
|
52
|
-
### With LRU Cache
|
|
53
|
-
|
|
54
|
-
```typescript
|
|
55
|
-
import { createFsStorageWithCache } from '@casfa/storage-fs';
|
|
56
|
-
|
|
57
|
-
const storage = createFsStorageWithCache({
|
|
58
|
-
basePath: '/var/cas/data',
|
|
59
|
-
cacheSize: 1000, // Max items in cache
|
|
60
|
-
cacheMaxAge: 60000, // TTL in milliseconds
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
// Cache is automatically managed
|
|
64
|
-
const data = await storage.get('node:abcd1234...'); // May hit cache
|
|
65
|
-
```
|
|
66
|
-
|
|
67
|
-
## Configuration
|
|
68
|
-
|
|
69
|
-
```typescript
|
|
70
|
-
interface FsStorageConfig {
|
|
71
|
-
// Required: Base directory for storage
|
|
72
|
-
basePath: string;
|
|
73
|
-
|
|
74
|
-
// Optional: File permissions (default: 0o644)
|
|
75
|
-
fileMode?: number;
|
|
76
|
-
|
|
77
|
-
// Optional: Directory permissions (default: 0o755)
|
|
78
|
-
dirMode?: number;
|
|
79
|
-
}
|
|
80
|
-
```
|
|
81
|
-
|
|
82
|
-
### Cache Options
|
|
83
|
-
|
|
84
|
-
```typescript
|
|
85
|
-
interface FsStorageWithCacheConfig extends FsStorageConfig {
|
|
86
|
-
// Max items in LRU cache (default: 1000)
|
|
87
|
-
cacheSize?: number;
|
|
88
|
-
|
|
89
|
-
// Cache TTL in milliseconds (default: 60000)
|
|
90
|
-
cacheMaxAge?: number;
|
|
91
|
-
}
|
|
92
|
-
```
|
|
93
|
-
|
|
94
|
-
## API Reference
|
|
95
|
-
|
|
96
|
-
### Functions
|
|
97
|
-
|
|
98
|
-
- `createFsStorage(config)` - Create storage without cache
|
|
99
|
-
- `createFsStorageWithCache(config)` - Create storage with LRU cache
|
|
100
|
-
|
|
101
|
-
### StorageProvider Interface
|
|
102
|
-
|
|
103
|
-
```typescript
|
|
104
|
-
interface StorageProvider {
|
|
105
|
-
get(key: string): Promise<Uint8Array | null>;
|
|
106
|
-
put(key: string, data: Uint8Array): Promise<void>;
|
|
107
|
-
has(key: string): Promise<boolean>;
|
|
108
|
-
delete(key: string): Promise<boolean>;
|
|
109
|
-
}
|
|
110
|
-
```
|
|
111
|
-
|
|
112
|
-
## Performance Tips
|
|
113
|
-
|
|
114
|
-
1. **Use caching** for read-heavy workloads
|
|
115
|
-
2. **Use SSD storage** for better random access performance
|
|
116
|
-
3. **Monitor disk space** as CAS data is append-only by nature
|
|
117
|
-
4. Consider **separate partitions** for CAS data to prevent filling system disk
|
|
118
|
-
|
|
119
|
-
## Related Packages
|
|
120
|
-
|
|
121
|
-
- `@casfa/storage-core` - Core types and utilities
|
|
122
|
-
- `@casfa/storage-memory` - In-memory storage (for testing)
|
|
123
|
-
- `@casfa/storage-s3` - S3 storage (for cloud deployment)
|
|
124
|
-
|
|
125
|
-
## License
|
|
126
|
-
|
|
127
|
-
MIT
|
package/README.zh-CN.md
DELETED
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
# @casfa/storage-fs
|
|
2
|
-
|
|
3
|
-
基于文件系统的 CAS 存储提供者。
|
|
4
|
-
|
|
5
|
-
## 安装
|
|
6
|
-
|
|
7
|
-
```bash
|
|
8
|
-
bun add @casfa/storage-fs
|
|
9
|
-
```
|
|
10
|
-
|
|
11
|
-
## 概述
|
|
12
|
-
|
|
13
|
-
基于文件系统的 CAS(内容寻址存储)存储提供者。采用分片目录结构存储内容,以获得更好的文件系统性能。
|
|
14
|
-
|
|
15
|
-
### 存储结构
|
|
16
|
-
|
|
17
|
-
```
|
|
18
|
-
{basePath}/
|
|
19
|
-
├── ab/
|
|
20
|
-
│ └── cd/
|
|
21
|
-
│ └── abcd1234... (full hash)
|
|
22
|
-
├── ef/
|
|
23
|
-
│ └── 01/
|
|
24
|
-
│ └── ef012345...
|
|
25
|
-
└── ...
|
|
26
|
-
```
|
|
27
|
-
|
|
28
|
-
## 使用方法
|
|
29
|
-
|
|
30
|
-
### 基本用法
|
|
31
|
-
|
|
32
|
-
```typescript
|
|
33
|
-
import { createFsStorage } from '@casfa/storage-fs';
|
|
34
|
-
|
|
35
|
-
const storage = createFsStorage({
|
|
36
|
-
basePath: '/var/cas/data',
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
// 存储数据
|
|
40
|
-
await storage.put('node:abcd1234...', data);
|
|
41
|
-
|
|
42
|
-
// 检索数据
|
|
43
|
-
const data = await storage.get('node:abcd1234...');
|
|
44
|
-
|
|
45
|
-
// 检查是否存在
|
|
46
|
-
const exists = await storage.has('node:abcd1234...');
|
|
47
|
-
|
|
48
|
-
// 删除
|
|
49
|
-
const deleted = await storage.delete('node:abcd1234...');
|
|
50
|
-
```
|
|
51
|
-
|
|
52
|
-
### 带 LRU 缓存
|
|
53
|
-
|
|
54
|
-
```typescript
|
|
55
|
-
import { createFsStorageWithCache } from '@casfa/storage-fs';
|
|
56
|
-
|
|
57
|
-
const storage = createFsStorageWithCache({
|
|
58
|
-
basePath: '/var/cas/data',
|
|
59
|
-
cacheSize: 1000, // 缓存最大条目数
|
|
60
|
-
cacheMaxAge: 60000, // TTL(毫秒)
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
// 缓存自动管理
|
|
64
|
-
const data = await storage.get('node:abcd1234...'); // 可能命中缓存
|
|
65
|
-
```
|
|
66
|
-
|
|
67
|
-
## 配置
|
|
68
|
-
|
|
69
|
-
```typescript
|
|
70
|
-
interface FsStorageConfig {
|
|
71
|
-
// 必需:存储基础目录
|
|
72
|
-
basePath: string;
|
|
73
|
-
|
|
74
|
-
// 可选:文件权限(默认: 0o644)
|
|
75
|
-
fileMode?: number;
|
|
76
|
-
|
|
77
|
-
// 可选:目录权限(默认: 0o755)
|
|
78
|
-
dirMode?: number;
|
|
79
|
-
}
|
|
80
|
-
```
|
|
81
|
-
|
|
82
|
-
### 缓存选项
|
|
83
|
-
|
|
84
|
-
```typescript
|
|
85
|
-
interface FsStorageWithCacheConfig extends FsStorageConfig {
|
|
86
|
-
// LRU 缓存最大条目数(默认: 1000)
|
|
87
|
-
cacheSize?: number;
|
|
88
|
-
|
|
89
|
-
// 缓存 TTL,单位毫秒(默认: 60000)
|
|
90
|
-
cacheMaxAge?: number;
|
|
91
|
-
}
|
|
92
|
-
```
|
|
93
|
-
|
|
94
|
-
## API 参考
|
|
95
|
-
|
|
96
|
-
### 函数
|
|
97
|
-
|
|
98
|
-
- `createFsStorage(config)` - 创建不带缓存的存储
|
|
99
|
-
- `createFsStorageWithCache(config)` - 创建带 LRU 缓存的存储
|
|
100
|
-
|
|
101
|
-
### StorageProvider 接口
|
|
102
|
-
|
|
103
|
-
```typescript
|
|
104
|
-
interface StorageProvider {
|
|
105
|
-
get(key: string): Promise<Uint8Array | null>;
|
|
106
|
-
put(key: string, data: Uint8Array): Promise<void>;
|
|
107
|
-
has(key: string): Promise<boolean>;
|
|
108
|
-
delete(key: string): Promise<boolean>;
|
|
109
|
-
}
|
|
110
|
-
```
|
|
111
|
-
|
|
112
|
-
## 性能建议
|
|
113
|
-
|
|
114
|
-
1. **使用缓存** 以应对读密集型工作负载
|
|
115
|
-
2. **使用 SSD 存储** 以获得更好的随机访问性能
|
|
116
|
-
3. **监控磁盘空间**,因为 CAS 数据本质上是只追加的
|
|
117
|
-
4. 考虑为 CAS 数据使用**独立分区**,防止占满系统磁盘
|
|
118
|
-
|
|
119
|
-
## 相关包
|
|
120
|
-
|
|
121
|
-
- `@casfa/storage-core` - 核心类型与工具
|
|
122
|
-
- `@casfa/storage-memory` - 内存存储(用于测试)
|
|
123
|
-
- `@casfa/storage-s3` - S3 存储(用于云端部署)
|
|
124
|
-
|
|
125
|
-
## 许可证
|
|
126
|
-
|
|
127
|
-
MIT
|