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

fix: circular dependencies #75

Closed
wants to merge 2 commits into from
Closed
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
11 changes: 2 additions & 9 deletions buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,13 @@ import * as math from './math.js'
import * as encoding from './encoding.js'
import * as decoding from './decoding.js'

export { createUint8ArrayViewFromArrayBuffer } from './common.js'

/**
* @param {number} len
*/
export const createUint8ArrayFromLen = len => new Uint8Array(len)

/**
* Create Uint8Array with initial content from buffer
*
* @param {ArrayBuffer} buffer
* @param {number} byteOffset
* @param {number} length
*/
export const createUint8ArrayViewFromArrayBuffer = (buffer, byteOffset, length) => new Uint8Array(buffer, byteOffset, length)

/**
* Create Uint8Array with initial content from buffer
*
Expand Down
14 changes: 14 additions & 0 deletions common.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* Common Functions.
*
* @module common
*/

/**
* Create Uint8Array with initial content from buffer
*
* @param {ArrayBuffer} buffer
* @param {number} byteOffset
* @param {number} length
*/
export const createUint8ArrayViewFromArrayBuffer = (buffer, byteOffset, length) => new Uint8Array(buffer, byteOffset, length)
4 changes: 2 additions & 2 deletions decoding.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
* @module decoding
*/

import * as buffer from './buffer.js'
import * as common from './common.js'
import * as binary from './binary.js'
import * as math from './math.js'
import * as number from './number.js'
Expand Down Expand Up @@ -101,7 +101,7 @@ export const clone = (decoder, newPos = decoder.pos) => {
* @return {Uint8Array}
*/
export const readUint8Array = (decoder, len) => {
const view = buffer.createUint8ArrayViewFromArrayBuffer(decoder.arr.buffer, decoder.pos + decoder.arr.byteOffset, len)
const view = common.createUint8ArrayViewFromArrayBuffer(decoder.arr.buffer, decoder.pos + decoder.arr.byteOffset, len)
decoder.pos += len
return view
}
Expand Down
6 changes: 3 additions & 3 deletions encoding.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
* @module encoding
*/

import * as buffer from './buffer.js'
import * as common from './common.js'
import * as math from './math.js'
import * as number from './number.js'
import * as binary from './binary.js'
Expand Down Expand Up @@ -101,7 +101,7 @@ export const toUint8Array = encoder => {
uint8arr.set(d, curPos)
curPos += d.length
}
uint8arr.set(buffer.createUint8ArrayViewFromArrayBuffer(encoder.cbuf.buffer, 0, encoder.cpos), curPos)
uint8arr.set(common.createUint8ArrayViewFromArrayBuffer(encoder.cbuf.buffer, 0, encoder.cpos), curPos)
return uint8arr
}

Expand All @@ -115,7 +115,7 @@ export const toUint8Array = encoder => {
export const verifyLen = (encoder, len) => {
const bufferLen = encoder.cbuf.length
if (bufferLen - encoder.cpos < len) {
encoder.bufs.push(buffer.createUint8ArrayViewFromArrayBuffer(encoder.cbuf.buffer, 0, encoder.cpos))
encoder.bufs.push(common.createUint8ArrayViewFromArrayBuffer(encoder.cbuf.buffer, 0, encoder.cpos))
encoder.cbuf = new Uint8Array(math.max(bufferLen, len) * 2)
encoder.cpos = 0
}
Expand Down