Skip to content

Commit

Permalink
Merge pull request #87 from datopian/fix/rows
Browse files Browse the repository at this point in the history
[hex][xs]: Chnage base64 encoding to hex for generating the hashes - #86
  • Loading branch information
Karlen Manaseryan authored Sep 16, 2020
2 parents 4c3cc45 + f07df2e commit 3027db3
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
6 changes: 4 additions & 2 deletions browser-test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ describe('FileInterface', function () {

const hash = await file.hash()
const hashSha256 = await file.hashSha256()
expect(hash).toBe('sGYdlWZJioAPv5U2XOKHRw==')
expect(hashSha256).toBe('2dR7kKyWB8URH/moOqN7wQ4FjOYgbAC2YmreCReE4Jg=')
expect(hash).toBe('b0661d9566498a800fbf95365ce28747')
expect(hashSha256).toBe(
'd9d47b90ac9607c5111ff9a83aa37bc10e058ce6206c00b6626ade091784e098'
)
expect(file.displayName).toBe('FileInterface')
expect(file.size).toBe(46)
})
Expand Down
8 changes: 4 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,12 +185,12 @@ class FileInterface extends File {

async hash() {
const text = await this.descriptor.text()
return crypto.createHash('md5').update(text).digest('base64')
return crypto.createHash('md5').update(text).digest('hex')
}

async hashSha256() {
const text = await this.descriptor.text()
return crypto.createHash('sha256').update(text).digest('base64')
return crypto.createHash('sha256').update(text).digest('hex')
}
}

Expand All @@ -217,7 +217,7 @@ class FileLocal extends File {
return crypto
.createHash('md5')
.update(fs.readFileSync(this.path))
.digest('base64')
.digest('hex')
}

get encoding() {
Expand Down Expand Up @@ -302,7 +302,7 @@ class FileInline extends File {
}

get hash() {
return crypto.createHash('md5').update(this._buffer).digest('base64')
return crypto.createHash('md5').update(this._buffer).digest('hex')
}

stream() {
Expand Down
2 changes: 1 addition & 1 deletion test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ test('parsePath function with remote url without conventional filename', t => {
const testFile = async (t, file) => {
t.is(file.path, 'test/fixtures/sample.csv')
t.is(file.size, 46)
t.is(file.hash, 'sGYdlWZJioAPv5U2XOKHRw==')
t.is(file.hash, 'b0661d9566498a800fbf95365ce28747')
await testFileStream(t, file)
}

Expand Down

0 comments on commit 3027db3

Please sign in to comment.