Skip to content

Commit 967074e

Browse files
committed
feat(crc32): input now accept string
1 parent ad9d0d6 commit 967074e

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

packages/crc32/index.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
export function crc32(input: Buffer, crc?: number): number
2-
export function crc32c(input: Buffer, crc?: number): number
1+
export function crc32(input: Buffer | string, crc?: number): number
2+
export function crc32c(input: Buffer | string, crc?: number): number

packages/crc32/index.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
11
const { locateBinding } = require('@node-rs/helper')
22

3-
module.exports = require(locateBinding(__dirname, 'crc32'))
3+
const binding = require(locateBinding(__dirname, 'crc32'))
4+
5+
module.exports = {
6+
crc32: function crc32(input, crc) {
7+
const _input = Buffer.isBuffer(input) ? input : Buffer.from(input)
8+
return binding.crc32(_input, crc)
9+
},
10+
crc32c: function crc32c(input, crc) {
11+
const _input = Buffer.isBuffer(input) ? input : Buffer.from(input)
12+
return binding.crc32c(_input, crc)
13+
},
14+
}

0 commit comments

Comments
 (0)