1 回答
TA贡献2036条经验 获得超8个赞
下面是一些框架代码,可帮助您入门:
function byteRangeTransform(start, end) {
let bytesSeen = 0;
return new TransformStream({
transform(chunk, controller) {
const chunkStart = bytesSeen;
const chunkEnd = bytesSeen + chunk.byteLength;
bytesSeen += chunk.byteLength;
// Six cases:
// 1. Chunk entirely before start
if (chunkEnd < start) {
return;
}
// 2. Chunk starts before start, ends between start and end
if (chunkStart < start && chunkEnd >= start && chunkEnd <= end) {
const slice = /* TODO */;
controller.enqueue(slice);
return;
}
// 3. Chunk starts before start, ends after end
if (chunkStart < start && chunkEnd > end) {
// TODO
}
// 4. Chunk starts after start, ends between start and end
// 5. Chunk starts after start, ends after end
// 6. Chunk starts after end
}
});
}
const onlyInRange = originalReadable.pipeThrough(byteRangeTransform(300, 900));
添加回答
举报