Skip to content
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
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -200,11 +200,11 @@
"docs": "aegir docs"
},
"dependencies": {
"multiformats": "^13.0.0"
"multiformats": "^14.0.0"
},
"devDependencies": {
"@types/benchmark": "^2.1.1",
"aegir": "^47.1.5",
"aegir": "^48.0.1",
"benchmark": "^2.1.4"
},
"imports": {
Expand Down
4 changes: 2 additions & 2 deletions src/alloc.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { asUint8Array } from '#util/as-uint8array'
* Returns a `Uint8Array` of the requested size. Referenced memory will
* be initialized to 0.
*/
export function alloc (size: number = 0): Uint8Array {
export function alloc (size: number = 0): Uint8Array<ArrayBuffer> {
return asUint8Array(Buffer.alloc(size))
}

Expand All @@ -14,6 +14,6 @@ export function alloc (size: number = 0): Uint8Array {
* uninitialized memory. Only use if you are certain you will immediately
* overwrite every value in the returned `Uint8Array`.
*/
export function allocUnsafe (size: number = 0): Uint8Array {
export function allocUnsafe (size: number = 0): Uint8Array<ArrayBuffer> {
return asUint8Array(Buffer.allocUnsafe(size))
}
4 changes: 2 additions & 2 deletions src/alloc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Returns a `Uint8Array` of the requested size. Referenced memory will
* be initialized to 0.
*/
export function alloc (size: number = 0): Uint8Array {
export function alloc (size: number = 0): Uint8Array<ArrayBuffer> {
return new Uint8Array(size)
}

Expand All @@ -11,6 +11,6 @@ export function alloc (size: number = 0): Uint8Array {
* uninitialized memory. Only use if you are certain you will immediately
* overwrite every value in the returned `Uint8Array`.
*/
export function allocUnsafe (size: number = 0): Uint8Array {
export function allocUnsafe (size: number = 0): Uint8Array<ArrayBuffer> {
return new Uint8Array(size)
}
2 changes: 1 addition & 1 deletion src/concat.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ import { asUint8Array } from '#util/as-uint8array'
/**
* Returns a new Uint8Array created by concatenating the passed Uint8Arrays
*/
export function concat (arrays: Uint8Array[], length?: number): Uint8Array {
export function concat (arrays: Uint8Array[], length?: number): Uint8Array<ArrayBuffer> {
return asUint8Array(Buffer.concat(arrays, length))
}
2 changes: 1 addition & 1 deletion src/concat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { asUint8Array } from '#util/as-uint8array'
/**
* Returns a new Uint8Array created by concatenating the passed Uint8Arrays
*/
export function concat (arrays: Uint8Array[], length?: number): Uint8Array {
export function concat (arrays: Uint8Array[], length?: number): Uint8Array<ArrayBuffer> {
if (length == null) {
length = arrays.reduce((acc, curr) => acc + curr.length, 0)
}
Expand Down
2 changes: 1 addition & 1 deletion src/from-string.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export type { SupportedEncodings }
*
* Also `ascii` which is similar to node's 'binary' encoding.
*/
export function fromString (string: string, encoding: SupportedEncodings = 'utf8'): Uint8Array {
export function fromString (string: string, encoding: SupportedEncodings = 'utf8'): Uint8Array<ArrayBuffer> {
const base = bases[encoding]

if (base == null) {
Expand Down
2 changes: 1 addition & 1 deletion src/from-string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export type { SupportedEncodings }
*
* Also `ascii` which is similar to node's 'binary' encoding.
*/
export function fromString (string: string, encoding: SupportedEncodings = 'utf8'): Uint8Array {
export function fromString (string: string, encoding: SupportedEncodings = 'utf8'): Uint8Array<ArrayBuffer> {
const base = bases[encoding]

if (base == null) {
Expand Down
10 changes: 8 additions & 2 deletions src/util/as-uint8array.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
* To guarantee Uint8Array semantics, convert nodejs Buffers
* into vanilla Uint8Arrays
*/
export function asUint8Array (buf: Uint8Array): Uint8Array {
return new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength)
export function asUint8Array (buf: Uint8Array): Uint8Array<ArrayBuffer> {
if (buf.buffer instanceof ArrayBuffer) {
return new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength)
}

const b = buf.slice()

return new Uint8Array(b.buffer, 0, b.byteLength)
}
14 changes: 12 additions & 2 deletions src/util/as-uint8array.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
function isByteArrayWithArrayBuffer (b?: Uint8Array): b is Uint8Array<ArrayBuffer> {
return b?.buffer instanceof ArrayBuffer
}

/**
* To guarantee Uint8Array semantics, convert nodejs Buffers
* into vanilla Uint8Arrays
*/
export function asUint8Array (buf: Uint8Array): Uint8Array {
return buf
export function asUint8Array (buf: Uint8Array): Uint8Array<ArrayBuffer> {
if (isByteArrayWithArrayBuffer(buf)) {
return buf
}

const b = buf.slice()

return new Uint8Array(b.buffer, 0, b.byteLength)
}
2 changes: 1 addition & 1 deletion src/util/bases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { bases } from 'multiformats/basics'
import type { MultibaseCodec } from 'multiformats'
import { allocUnsafe } from '#alloc'

function createCodec (name: string, prefix: string, encode: (buf: Uint8Array) => string, decode: (str: string) => Uint8Array): MultibaseCodec<any> {
function createCodec (name: string, prefix: string, encode: (buf: Uint8Array) => string, decode: (str: string) => Uint8Array<ArrayBuffer>): MultibaseCodec<any> {
return {
name,
prefix,
Expand Down
2 changes: 1 addition & 1 deletion src/xor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { asUint8Array } from '#util/as-uint8array'
/**
* Returns the xor distance between two Uint8Arrays
*/
export function xor (a: Uint8Array, b: Uint8Array): Uint8Array {
export function xor (a: Uint8Array, b: Uint8Array): Uint8Array<ArrayBuffer> {
if (a.length !== b.length) {
throw new Error('Inputs should have the same length')
}
Expand Down
2 changes: 1 addition & 1 deletion test/equals.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect } from 'aegir/chai'
import { equals } from '../src/equals.js'
import { equals } from '../src/equals.ts'

describe('Uint8Array equals', () => {
it('finds two Uint8Arrays equal', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/from-string.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect } from 'aegir/chai'
import bases from '../src/util/bases.js'
import bases from '../src/util/bases.ts'
import type { SupportedEncodings } from '#from-string'
import { fromString } from '#from-string'
import { toString } from '#to-string'
Expand Down
2 changes: 1 addition & 1 deletion test/xor-compare.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect } from 'aegir/chai'
import { xorCompare } from '../src/xor-compare.js'
import { xorCompare } from '../src/xor-compare.ts'

describe('xor-compare', () => {
it('compare', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/xor.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect } from 'aegir/chai'
import { xor } from '../src/xor.js'
import { xor } from '../src/xor.ts'

describe('Uint8Array xor', () => {
it('xors 1,0 and 0,1', () => {
Expand Down
Loading