Skip to content

Commit

Permalink
Merge PR #6 from 'nodech/ts-lint'
Browse files Browse the repository at this point in the history
  • Loading branch information
nodech committed Aug 31, 2023
2 parents 8d3c028 + d1dbafd commit 06ae226
Show file tree
Hide file tree
Showing 9 changed files with 335 additions and 34 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,17 @@ jobs:
node-version: 20.x

- name: Install tools
run: npm install --location=global bslint
run: npm install --location=global bslint typescript

- name: Install dependencies
run: npm install

- name: Lint
run: npm run lint

- name: Lint types
run: npm run lint-types

test:
name: Test
runs-on: ubuntu-latest
Expand Down
5 changes: 5 additions & 0 deletions lib/encoding.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,14 @@ const BIG_ENDIAN = F328_ARRAY[3] === 0;

// eslint-disable-next-line
const BI = typeof BigInt === 'function' ? BigInt : (function(x) { return 0; });

// @ts-ignore
const BIG_U56_MAX = (BI(1) << BI(56)) - BI(1);
// @ts-ignore
const BIG_U64_MAX = (BI(1) << BI(64)) - BI(1);
// @ts-ignore
const BIG_U128_MAX = (BI(1) << BI(128)) - BI(1);
// @ts-ignore
const BIG_U256_MAX = (BI(1) << BI(256)) - BI(1);

/*
Expand Down
24 changes: 14 additions & 10 deletions lib/reader.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ const EMPTY = Buffer.alloc(0);
*/

class BufferReader {
/** @type {Buffer} */
data;

/**
* Create a buffer reader.
* @constructor
Expand Down Expand Up @@ -53,7 +56,7 @@ class BufferReader {

/**
* Get total size of passed-in Buffer.
* @returns {Buffer}
* @returns {Number}
*/

getSize() {
Expand Down Expand Up @@ -115,7 +118,7 @@ class BufferReader {
/**
* Stop reading. Pop the start position off the stack
* and return the data read.
* @param {Bolean?} zeroCopy - Do a fast buffer
* @param {Boolean} [zeroCopy=false] Do a fast buffer
* slice instead of allocating a new buffer (warning:
* may cause memory leaks if not used with care).
* @returns {Buffer} Data read.
Expand Down Expand Up @@ -880,7 +883,7 @@ class BufferReader {
/**
* Read N bytes (will do a fast slice if zero copy).
* @param {Number} size
* @param {Bolean?} zeroCopy - Do a fast buffer
* @param {Boolean?} [zeroCopy = false] - Do a fast buffer
* slice instead of allocating a new buffer (warning:
* may cause memory leaks if not used with care).
* @returns {Buffer}
Expand Down Expand Up @@ -908,7 +911,7 @@ class BufferReader {

/**
* Read a varint number of bytes (will do a fast slice if zero copy).
* @param {Bolean?} zeroCopy - Do a fast buffer
* @param {Boolean} [zeroCopy=false] - Do a fast buffer
* slice instead of allocating a new buffer (warning:
* may cause memory leaks if not used with care).
* @returns {Buffer}
Expand All @@ -930,6 +933,7 @@ class BufferReader {
this.check(size);

const data = this.data.slice(0, this.offset + size);
// @ts-ignore
const br = new this.constructor(data);

br.offset = this.offset;
Expand All @@ -942,7 +946,7 @@ class BufferReader {
/**
* Read a string.
* @param {Number} size
* @param {String} enc - Any buffer-supported encoding.
* @param {BufferEncoding} enc - Any buffer-supported encoding.
* @returns {String}
*/

Expand All @@ -964,8 +968,8 @@ class BufferReader {

/**
* Read a 32-byte hash.
* @param {String} enc - `"hex"` or `null`.
* @returns {Hash|Buffer}
* @param {BufferEncoding} enc - `"hex"` or `null`.
* @returns {Buffer|String}
*/

readHash(enc) {
Expand All @@ -976,7 +980,7 @@ class BufferReader {

/**
* Read string of a varint length.
* @param {String} enc - Any buffer-supported encoding.
* @param {BufferEncoding} enc - Any buffer-supported encoding.
* @param {Number?} limit - Size limit.
* @returns {String}
*/
Expand All @@ -998,7 +1002,7 @@ class BufferReader {

/**
* Read a null-terminated string.
* @param {String} enc - Any buffer-supported encoding.
* @param {BufferEncoding} enc - Any buffer-supported encoding.
* @returns {String}
*/

Expand Down Expand Up @@ -1027,7 +1031,7 @@ class BufferReader {

/**
* Create a checksum from the last start position.
* @param {Function} hash
* @param {Function|Object} hash
* @returns {Number} Checksum.
*/

Expand Down
Loading

0 comments on commit 06ae226

Please sign in to comment.