Skip to content

Commit 42ec5f5

Browse files
authored
feat: pass file name along with progress (#87)
When importing and reporting progress we pass the current filename as part of progress events in the [http server](https://github.com/ipfs/js-ipfs/blob/master/packages/ipfs-http-server/src/api/resources/files-regular.js#L254-L255) To do the same thing with core we need access to the filename as part of the progress handler.
1 parent f10454b commit 42ec5f5

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

Diff for: packages/ipfs-unixfs-importer/src/dag-builder/file/buffer-importer.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const {
99
async function * bufferImporter (file, source, block, options) {
1010
for await (let buffer of source) {
1111
yield async () => {
12-
options.progress(buffer.length)
12+
options.progress(buffer.length, file.path)
1313
let unixfs
1414

1515
const opts = {

Diff for: packages/ipfs-unixfs-importer/test/importer.spec.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -647,19 +647,20 @@ strategies.forEach((strategy) => {
647647

648648
it('will call an optional progress function', async () => {
649649
const maxChunkSize = 2048
650+
const path = '1.2MiB.txt'
650651

651652
const options = {
652653
progress: spy(),
653654
maxChunkSize
654655
}
655656

656657
await all(importer([{
657-
path: '1.2MiB.txt',
658+
path,
658659
content: bigFile
659660
}], block, options))
660661

661662
expect(options.progress.called).to.equal(true)
662-
expect(options.progress.args[0][0]).to.equal(maxChunkSize)
663+
expect(options.progress.args[0]).to.deep.equal([maxChunkSize, path])
663664
})
664665

665666
it('will import files with CID version 1', async () => {

0 commit comments

Comments
 (0)