Support for concatenating multiple files
- Dominant language
- JavaScript
- Stars
- 11
- Forks
- 6
- PR merge metrics
- No merged PRs in 30d
Description
It would be great if there was documentation / examples, or even a utility function for concatenating existing file links, to make a new file. After debugging, I was able to come up with something that works, but not sure if this is the 'right' way to do it, and doesn't using the task queue...
The writer is the top-level writer from `UnixFS.createWriter()` and `links` is an array of links returned after multiple `fileWriter.close()` calls.
The below produces a concatenated file, using `createAdvancedFile`.
```
async function concat(writer, links) {
const {fileEncoder, hasher, linker} = writer.settings;
const advanced = fileEncoder.createAdvancedFile(links);
const bytes = fileEncoder.encode(advanced);
const hash = await hasher.digest(bytes);
const cid = linker.createLink(fileEncoder.code, hash);
const block = { bytes, cid };
// correct to access underlying writer like this?
writer.writer.write(block);
const link = {
cid,
contentByteLength: fileEncoder.cumulativeContentByteLength(links),
dagByteLength: fileEncoder.cumulativeDagByteLength(bytes, links),
};
return link;
}
```
Contributor guide
No contributing guide indexed for this repository
Research direction
Begin at UnixFS.createWriter(), fileWriter.close(), and the createAdvancedFile flow shown; inspect how writer.settings and the task queue are intended to be used. Done means the project has a documented way to concatenate existing links, or a confirmed utility API, with its task-queue usage clarified.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- data, documentation
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100