Skip to content
This repository was archived by the owner on Mar 10, 2020. It is now read-only.

docs: update files.flush return type #579

Merged
merged 3 commits into from
Jan 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions SPEC/FILES.md
Original file line number Diff line number Diff line change
Expand Up @@ -1204,22 +1204,22 @@ await ipfs.files.mv('/src-file1', '/src-file2', '/dst-dir')

> Flush a given path's data to the disk

##### `ipfs.files.flush([...paths])`
##### `ipfs.files.flush([path])`

Where:

- `paths` are optional string paths to flush (default: `/`)
- `path` is an optional string path to flush (default: `/`)

**Returns**

| Type | Description |
| -------- | -------- |
| `Promise<void>` | If successfully copied. Otherwise an error will be thrown |
| `Promise<CID>` | The CID of the path that has been flushed |

**Example:**

```JavaScript
await ipfs.files.flush('/')
const cid = await ipfs.files.flush('/')
```

#### `files.ls`
Expand Down
13 changes: 11 additions & 2 deletions src/files-mfs/flush.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,22 @@ module.exports = (common, options) => {
}
})

it('should flush root', () => ipfs.files.flush())
it('should flush root', async () => {
const root = await ipfs.files.stat('/')
const flushed = await ipfs.files.flush()

expect(root.hash).to.equal(flushed.toString())
})

it('should flush specific dir', async () => {
const testDir = `/test-${hat()}`

await ipfs.files.mkdir(testDir, { parents: true })
await ipfs.files.flush(testDir)

const dirStats = await ipfs.files.stat(testDir)
const flushed = await ipfs.files.flush(testDir)

expect(dirStats.hash).to.equal(flushed.toString())
})
})
}