Skip to content

Commit

Permalink
feat: improve getMetadata
Browse files Browse the repository at this point in the history
  • Loading branch information
nassiharel committed Sep 24, 2020
1 parent 79e172c commit d5b768a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
11 changes: 4 additions & 7 deletions lib/fs-adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,10 @@ class FSAdapter {
}

async getMetadata(options) {
const res = await fs.stat(pathLib.join(this._baseDirectory, options.path));
return { size: res.size };
}

async getHeader(options) {
const header = await this.seek({ path: options.path, start: 0, end: 8 });
return header;
const { path } = options;
const stat = await fs.stat(pathLib.join(this._baseDirectory, path));
const header = await this.seek({ path, start: 0, end: 8 });
return { size: stat.size, metadata: { header } };
}

async seek(options) {
Expand Down
4 changes: 2 additions & 2 deletions tests/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,8 @@ describe('fs-adapter', () => {
const metadata = { header };
const data = Buffer.alloc(10);
const link = await adapter.originalPut({ path: path.join(DIR_NAMES.HKUBE, uid), metadata, data });
const res = await adapter.getHeader(link);
expect(res).to.eql(header);
const res = await adapter.getMetadata(link);
expect(res.metadata).to.eql(metadata);
});
it('should put and get buffer header and data', async () => {
const uid = uuid();
Expand Down

0 comments on commit d5b768a

Please sign in to comment.