Skip to content

Commit 0fb521c

Browse files
Pedro Santosjacobheun
Pedro Santos
authored andcommitted
feat: remove options object from stat method (#216)
1 parent 9a13115 commit 0fb521c

File tree

4 files changed

+7
-41
lines changed

4 files changed

+7
-41
lines changed

README.md

+2-4
Original file line numberDiff line numberDiff line change
@@ -269,12 +269,10 @@ Sets the API address.
269269

270270
* `value` should be a [Multiaddr](https://github.com/multiformats/js-multiaddr) or a String representing a valid one.
271271

272-
### `Promise<Object> repo.stat ([options])`
272+
### `Promise<Object> repo.stat ()`
273273

274274
Gets the repo status.
275275

276-
`options` is an object which might contain the key `human`, which is a boolean indicating whether or not the `repoSize` should be displayed in MiB or not.
277-
278276
Returned promise resolves to an `Object` with the following keys:
279277

280278
- `numObjects`
@@ -322,7 +320,7 @@ Returned promise resolves to a `boolean` indicating the existence of the lock.
322320

323321
### Migrations
324322

325-
When there is a new repo migration and the version of repo is increased, don't
323+
When there is a new repo migration and the version of repo is increased, don't
326324
forget to propagate the changes into the test repo (`test/test-repo`).
327325

328326
**For tools that run mainly in the browser environment, be aware that disabling automatic

package.json

-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@
7171
"just-safe-set": "^2.1.0",
7272
"lodash.has": "^4.5.2",
7373
"p-queue": "^6.0.0",
74-
"pretty-bytes": "^5.3.0",
7574
"proper-lockfile": "^4.0.0",
7675
"sort-keys": "^3.0.0"
7776
},

src/index.js

+5-15
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ const debug = require('debug')
77
const Big = require('bignumber.js')
88
const errcode = require('err-code')
99
const migrator = require('ipfs-repo-migrations')
10-
const prettyBytes = require('pretty-bytes')
1110
const bytes = require('bytes')
1211

1312
const constants = require('./constants')
@@ -247,12 +246,9 @@ class IpfsRepo {
247246
/**
248247
* Get repo status.
249248
*
250-
* @param {Object} options
251-
* @param {Boolean} options.human
252-
* @return {Object}
249+
* @returns {Object}
253250
*/
254-
async stat (options) {
255-
options = Object.assign({}, { human: false }, options)
251+
async stat () {
256252
const [storageMax, blocks, version, datastore, keys] = await Promise.all([
257253
this._storageMaxStat(),
258254
this._blockStat(),
@@ -266,16 +262,10 @@ class IpfsRepo {
266262

267263
return {
268264
repoPath: this.path,
269-
storageMax: options.human
270-
? prettyBytes(storageMax.toNumber()).toUpperCase()
271-
: storageMax,
265+
storageMax,
272266
version: version,
273-
numObjects: options.human
274-
? blocks.count.toNumber()
275-
: blocks.count,
276-
repoSize: options.human
277-
? prettyBytes(size.toNumber()).toUpperCase()
278-
: size
267+
numObjects: blocks.count,
268+
repoSize: size
279269
}
280270
}
281271

test/stat-test.js

-21
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ chai.use(require('dirty-chai'))
66
const expect = chai.expect
77
const Block = require('ipfs-block')
88
const CID = require('cids')
9-
const prettyBytes = require('pretty-bytes')
109

1110
module.exports = (repo) => {
1211
describe('stat', () => {
@@ -32,25 +31,5 @@ module.exports = (repo) => {
3231
expect(stats.repoSize > '0').to.eql(true)
3332
expect(stats.storageMax > '0').to.eql(true)
3433
})
35-
36-
it('get human stats', async () => {
37-
const { repoSize, storageMax } = await repo.stat()
38-
39-
const humanizedRepoSize = prettyBytes(repoSize.toNumber()).toUpperCase()
40-
const humanizedStorageMax = prettyBytes(storageMax.toNumber()).toUpperCase()
41-
42-
const humanizedStats = await repo.stat({ human: true })
43-
44-
expect(humanizedStats).to.exist()
45-
expect(humanizedStats).to.have.property('numObjects')
46-
expect(humanizedStats).to.have.property('version').and.be.above(0)
47-
expect(humanizedStats).to.have.property('repoPath')
48-
expect(humanizedStats).to.have.property('repoSize').that.equals(humanizedRepoSize)
49-
expect(humanizedStats).to.have.property('storageMax').that.equals(humanizedStorageMax)
50-
51-
expect(humanizedStats.numObjects > '0').to.eql(true)
52-
expect(humanizedStats.repoSize > '0').to.eql(true)
53-
expect(humanizedStats.storageMax > '0').to.eql(true)
54-
})
5534
})
5635
}

0 commit comments

Comments
 (0)