Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deps: upgrade uint8-varint to 2.x.x #94

Merged
merged 2 commits into from
Aug 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"
}
}
6 changes: 3 additions & 3 deletions src/decode.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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
}
Expand Down
6 changes: 3 additions & 3 deletions src/encode.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion test/decode.from-reader.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down
5 changes: 2 additions & 3 deletions test/decode.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -33,7 +32,7 @@ describe('decode', () => {
const bytes = randomBytes(byteLength)

const input = new Uint8ArrayList(
unsigned.encode(byteLength),
varint.encode(byteLength),
bytes
)

Expand Down
2 changes: 1 addition & 1 deletion test/e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
10 changes: 5 additions & 5 deletions test/encode.single.spec.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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)', () => {
Expand Down
6 changes: 3 additions & 3 deletions test/encode.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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])
}
Expand All @@ -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])
}
Expand Down