diff --git a/package.json b/package.json index 3f7ee90..f5fc51f 100644 --- a/package.json +++ b/package.json @@ -175,12 +175,11 @@ "err-code": "^3.0.1", "it-reader": "^6.0.1", "it-stream-types": "^2.0.1", - "uint8-varint": "^1.0.1", + "uint8-varint": "^2.0.1", "uint8arraylist": "^2.0.0", "uint8arrays": "^4.0.2" }, "devDependencies": { - "@types/varint": "^6.0.0", "aegir": "^40.0.0", "iso-random-stream": "^2.0.0", "it-all": "^3.0.0", @@ -191,7 +190,6 @@ "it-pipe": "^3.0.0", "it-pushable": "^3.0.0", "p-defer": "^4.0.0", - "random-int": "^3.0.0", - "varint": "^6.0.0" + "random-int": "^3.0.0" } } diff --git a/src/decode.ts b/src/decode.ts index eb4b66b..759e0a7 100644 --- a/src/decode.ts +++ b/src/decode.ts @@ -1,7 +1,7 @@ /* eslint max-depth: ["error", 6] */ import errCode from 'err-code' -import { unsigned } from 'uint8-varint' +import * as varint from 'uint8-varint' import { Uint8ArrayList } from 'uint8arraylist' import { isAsyncIterable } from './utils.js' import type { LengthDecoderFunction } from './index.js' @@ -39,8 +39,8 @@ enum ReadMode { } const defaultDecoder: LengthDecoderFunction = (buf) => { - const length = unsigned.decode(buf) - defaultDecoder.bytes = unsigned.encodingLength(length) + const length = varint.decode(buf) + defaultDecoder.bytes = varint.encodingLength(length) return length } diff --git a/src/encode.ts b/src/encode.ts index ace52bc..4cd01a9 100644 --- a/src/encode.ts +++ b/src/encode.ts @@ -1,4 +1,4 @@ -import { unsigned } from 'uint8-varint' +import * as varint from 'uint8-varint' import { Uint8ArrayList } from 'uint8arraylist' import { allocUnsafe } from 'uint8arrays/alloc' import { isAsyncIterable } from './utils.js' @@ -10,10 +10,10 @@ interface EncoderOptions { } const defaultEncoder: LengthEncoderFunction = (length) => { - const lengthLength = unsigned.encodingLength(length) + const lengthLength = varint.encodingLength(length) const lengthBuf = allocUnsafe(lengthLength) - unsigned.encode(length, lengthBuf) + varint.encode(length, lengthBuf) defaultEncoder.bytes = lengthLength diff --git a/test/decode.from-reader.spec.ts b/test/decode.from-reader.spec.ts index 6ee00a7..946e73a 100644 --- a/test/decode.from-reader.spec.ts +++ b/test/decode.from-reader.spec.ts @@ -3,9 +3,9 @@ import randomBytes from 'iso-random-stream/src/random.js' import all from 'it-all' import { pipe } from 'it-pipe' import { reader } from 'it-reader' +import * as varint from 'uint8-varint' import { Uint8ArrayList } from 'uint8arraylist' import { concat as uint8ArrayConcat } from 'uint8arrays/concat' -import varint from 'varint' import * as lp from '../src/index.js' import { times, someBytes } from './helpers/index.js' diff --git a/test/decode.spec.ts b/test/decode.spec.ts index 573187b..b8fd8d2 100644 --- a/test/decode.spec.ts +++ b/test/decode.spec.ts @@ -5,10 +5,9 @@ import { block } from 'it-block' import { pipe } from 'it-pipe' import defer from 'p-defer' import randomInt from 'random-int' -import { unsigned } from 'uint8-varint' +import * as varint from 'uint8-varint' import { Uint8ArrayList } from 'uint8arraylist' import { concat as uint8ArrayConcat } from 'uint8arrays/concat' -import varint from 'varint' import { MAX_LENGTH_LENGTH, MAX_DATA_LENGTH } from '../src/decode.js' import * as lp from '../src/index.js' import { times } from './helpers/index.js' @@ -33,7 +32,7 @@ describe('decode', () => { const bytes = randomBytes(byteLength) const input = new Uint8ArrayList( - unsigned.encode(byteLength), + varint.encode(byteLength), bytes ) diff --git a/test/e2e.spec.ts b/test/e2e.spec.ts index 6a69898..76f6d0d 100644 --- a/test/e2e.spec.ts +++ b/test/e2e.spec.ts @@ -5,10 +5,10 @@ import each from 'it-foreach' import map from 'it-map' import { pipe } from 'it-pipe' import { pushable } from 'it-pushable' +import * as varint from 'uint8-varint' import { Uint8ArrayList } from 'uint8arraylist' import { concat as uint8ArrayConcat } from 'uint8arrays/concat' import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' -import varint from 'varint' import * as lp from '../src/index.js' import { int32BEDecode } from './helpers/int32BE-decode.js' import { int32BEEncode } from './helpers/int32BE-encode.js' diff --git a/test/encode.single.spec.ts b/test/encode.single.spec.ts index 31e0ea8..f581327 100644 --- a/test/encode.single.spec.ts +++ b/test/encode.single.spec.ts @@ -1,5 +1,5 @@ import { expect } from 'aegir/chai' -import varint from 'varint' +import * as varint from 'uint8-varint' import * as lp from '../src/index.js' import { someBytes } from './helpers/index.js' import { int32BEEncode } from './helpers/int32BE-encode.js' @@ -9,18 +9,18 @@ describe('encode.single', () => { const input = someBytes() const output = lp.encode.single(input) - const length = varint.decode(output.slice()) + const length = varint.decode(output) expect(length).to.equal(input.length) - expect(output.slice(varint.decode.bytes)).to.deep.equal(input) + expect(output.slice(varint.encodingLength(output.byteLength))).to.deep.equal(input) }) it('should encode zero length as prefix', () => { const input = new Uint8Array(0) const output = lp.encode.single(input) - const length = varint.decode(output.slice()) + const length = varint.decode(output) expect(length).to.equal(input.length) - expect(output.slice(varint.decode.bytes)).to.deep.equal(input) + expect(output.slice(varint.encodingLength(output.byteLength))).to.deep.equal(input) }) it('should encode with custom length encoder (int32BE)', () => { diff --git a/test/encode.spec.ts b/test/encode.spec.ts index bbe849c..1222514 100644 --- a/test/encode.spec.ts +++ b/test/encode.spec.ts @@ -2,7 +2,7 @@ import { expect } from 'aegir/chai' import all from 'it-all' import { pipe } from 'it-pipe' import randomInt from 'random-int' -import { unsigned } from 'uint8-varint' +import * as varint from 'uint8-varint' import { Uint8ArrayList } from 'uint8arraylist' import * as lp from '../src/index.js' import { times, someBytes } from './helpers/index.js' @@ -23,7 +23,7 @@ describe('encode', () => { const prefix = output[i] const data = output[i + 1] - const length = unsigned.decode(prefix) + const length = varint.decode(prefix) expect(length).to.equal(data.length) expect(data).to.deep.equal(input[inputIndex]) } @@ -39,7 +39,7 @@ describe('encode', () => { const prefix = output[i] const data = output[i + 1] - const length = unsigned.decode(prefix) + const length = varint.decode(prefix) expect(length).to.equal(data.length) expect(data).to.deep.equal(input[inputIndex]) }