断开对象读取
将文件分割成块, 然后按需要读取块 .
示例来源
- 文件 - @ chunkd/ source- file (中文(简体) )
- AWS S3 - (英语) @ chunkd/ source-aws (原始内容存档于2018-09-31) (英语)
- 乌尔 - @ chunkd/ source-url (英语)
- Google 云号 - @ chunkd/ source-google-云
- 记忆 - @ chunkd/ source-memory (英语)
示例使用
获取数据
const source = new SourceUrl('https://example.com/foo')
// Read 1KB chunks
source.chunkSize = 1024;
// Read the first 2KB of the file, or two chunks of data, this will be one HTTP Range requests
if (!source.hasBytes(0, 2048)) await source.loadBytes(0, 2048)
const bytes = source.bytes(0, 2048);
同时获取多个区域
const source = new SourceUrl('https://example.com/foo')
// Read 1KB chunks
source.chunkSize = 1024;
// Read in the first two KB and 1KB starting at 4KB
// This will do one HTTP Range request for all of the data even though 2048-4096 has not been requested
// Chunks 0 (0-1024), 1 (1024-2048), 2 (2048-3096) 3 (3096-4096) and 4 (4096 - 5120) will be fetched
await Promise.all([
source.loadBytes(0, 2048),
source.loadBytes(4096, 1024)
])
const bytes = source.bytes(0, 5120);
读取原始字节
const source = new SourceUrl('https://example.com/foo')
if (!source.hasBytes(0, 1024)) await source.loadBytes(0, 1024)
// Read a UInt8 starting at offset 0
const firstNumber = source.getUint8(0);
// Read a buffer from offset 10, with length of 100
const firstBuffer = source.bytes(10, 100)