Skip to content

Commit

Permalink
Remove long
Browse files Browse the repository at this point in the history
  • Loading branch information
cmdcolin committed Nov 13, 2023
1 parent 139f2db commit a1d6055
Show file tree
Hide file tree
Showing 7 changed files with 2,258 additions and 2,141 deletions.
18 changes: 4 additions & 14 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,34 +1,28 @@
## [1.1.14](https://github.com/GMOD/twobit-js/compare/v1.1.13...v1.1.14) (2022-07-18)



- Update generic-filehandle 2->3

<a name="1.1.13"></a>
## [1.1.13](https://github.com/GMOD/twobit-js/compare/v1.1.12...v1.1.13) (2022-03-30)


## [1.1.13](https://github.com/GMOD/twobit-js/compare/v1.1.12...v1.1.13) (2022-03-30)

- Publish src directory for better source maps

<a name="1.1.12"></a>
## [1.1.12](https://github.com/GMOD/twobit-js/compare/v1.1.11...v1.1.12) (2021-12-14)


## [1.1.12](https://github.com/GMOD/twobit-js/compare/v1.1.11...v1.1.12) (2021-12-14)

- Remove es6-promisify dependency

<a name="1.1.11"></a>
## [1.1.11](https://github.com/GMOD/twobit-js/compare/v1.1.10...v1.1.11) (2021-12-14)


## [1.1.11](https://github.com/GMOD/twobit-js/compare/v1.1.10...v1.1.11) (2021-12-14)

- Typescriptify codebase and add esm build

<a name="1.1.10"></a>
## [1.1.10](https://github.com/GMOD/twobit-js/compare/v1.1.9...v1.1.10) (2019-10-06)


## [1.1.10](https://github.com/GMOD/twobit-js/compare/v1.1.9...v1.1.10) (2019-10-06)

- Small refactor of `filehandle.read()` to make it more robust

Expand All @@ -38,13 +32,10 @@

## [1.1.8](https://github.com/GMOD/twobit-js/compare/v1.1.6...v1.1.8) (2019-04-04)



- Add @babel/runtime-corejs2 as a runtime dependency

## [1.1.7](https://github.com/GMOD/twobit-js/compare/v1.1.6...v1.1.7) (2019-04-03)


- Use core-js to polyfill Object.values instead of polyfill library

## [1.1.6](https://github.com/GMOD/twobit-js/compare/v1.1.5...v1.1.6) (2019-04-03)
Expand All @@ -67,7 +58,6 @@

- Use @gmod/binary-parser


## 1.1.1

- Use babel-plugin-transform-runtime
Expand Down
36 changes: 18 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,26 +44,26 @@ const seqNames = await t.getSequenceNames()

##### Table of Contents

* [constructor](#constructor)
* [Parameters](#parameters)
* [getHeader](#getheader)
* [getIndex](#getindex)
* [getSequenceNames](#getsequencenames)
* [getSequenceSizes](#getsequencesizes)
* [getSequenceSize](#getsequencesize)
* [Parameters](#parameters-1)
* [getSequence](#getsequence)
* [Parameters](#parameters-2)
- [constructor](#constructor)
- [Parameters](#parameters)
- [getHeader](#getheader)
- [getIndex](#getindex)
- [getSequenceNames](#getsequencenames)
- [getSequenceSizes](#getsequencesizes)
- [getSequenceSize](#getsequencesize)
- [Parameters](#parameters-1)
- [getSequence](#getsequence)
- [Parameters](#parameters-2)

#### constructor

##### Parameters

* `args` **[object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)**&#x20;
- `args` **[object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)**&#x20;

* `args.filehandle` **Filehandle?** node fs.promises-like filehandle for the .2bit file.
Only needs to support `filehandle.read(buffer, offset, length, position)`
* `args.path` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** filesystem path for the .2bit file to open
- `args.filehandle` **Filehandle?** node fs.promises-like filehandle for the .2bit file.
Only needs to support `filehandle.read(buffer, offset, length, position)`
- `args.path` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** filesystem path for the .2bit file to open

#### getHeader

Expand All @@ -90,17 +90,17 @@ faster

##### Parameters

* `seqName` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** name of the sequence
- `seqName` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** name of the sequence

Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)** for the sequence's length, or undefined if it is not in the file

#### getSequence

##### Parameters

* `seqName` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** name of the sequence you want
* `regionStart` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)?** optional 0-based half-open start of the sequence region to fetch. (optional, default `0`)
* `regionEnd` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)?** optional 0-based half-open end of the sequence region to fetch. defaults to end of the sequence
- `seqName` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** name of the sequence you want
- `regionStart` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)?** optional 0-based half-open start of the sequence region to fetch. (optional, default `0`)
- `regionEnd` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)?** optional 0-based half-open end of the sequence region to fetch. defaults to end of the sequence

Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)** for a string of sequence bases

Expand Down
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
};
}
31 changes: 15 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,24 +39,23 @@
],
"dependencies": {
"@gmod/binary-parser": "^1.3.5",
"generic-filehandle": "^3.0.0",
"long": "^4.0.0"
"generic-filehandle": "^3.0.0"
},
"devDependencies": {
"@types/jest": "^29.2.4",
"@typescript-eslint/eslint-plugin": "^5.46.1",
"@typescript-eslint/parser": "^5.46.1",
"documentation": "^14.0.1",
"eslint": "^8.30.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-prettier": "^4.2.1",
"jest": "^29.3.1",
"prettier": "^2.8.1",
"rimraf": "^3.0.2",
"standard-changelog": "^2.0.27",
"ts-jest": "^29.0.3",
"typescript": "^4.9.4"
"@types/jest": "^29.5.3",
"@typescript-eslint/eslint-plugin": "^6.2.0",
"@typescript-eslint/parser": "^6.2.0",
"documentation": "^14.0.2",
"eslint": "^8.46.0",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-import": "^2.28.0",
"eslint-plugin-prettier": "^5.0.0",
"jest": "^29.6.2",
"prettier": "^3.1.0",
"rimraf": "^5.0.1",
"standard-changelog": "^5.0.0",
"ts-jest": "^29.1.1",
"typescript": "^5.1.6"
},
"publishConfig": {
"access": "public"
Expand Down
1 change: 0 additions & 1 deletion src/declare.d.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
declare module '@gmod/binary-parser'
declare module 'long'
19 changes: 4 additions & 15 deletions src/twoBitFile.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import Long from 'long'
import { LocalFile, GenericFilehandle } from 'generic-filehandle'
import { Parser } from '@gmod/binary-parser'

Expand Down Expand Up @@ -97,9 +96,7 @@ export default class TwoBitFile {
.uint8('nameLength')
.string('name', { length: 'nameLength' })
if (this.version === 1) {
indexEntryParser = indexEntryParser.buffer('offsetBytes', {
length: 8,
})
indexEntryParser = indexEntryParser.buffer('buf', { length: 8 })
} else {
indexEntryParser = indexEntryParser.uint32('offset')
}
Expand Down Expand Up @@ -197,17 +194,9 @@ export default class TwoBitFile {
const indexData = indexParser.parse(buffer).result.index
const index = {} as { [key: string]: number }
if (this.version === 1) {
indexData.forEach(
({ name, offsetBytes }: { name: string; offsetBytes: number }) => {
const long = Long.fromBytes(offsetBytes, true, !this.isBigEndian)
if (long.greaterThan(Number.MAX_SAFE_INTEGER)) {
throw new Error(
'integer overflow. File offset greater than 2^53-1 encountered. This library can only handle offsets up to 2^53-1.',
)
}
index[name] = long.toNumber()
},
)
indexData.forEach(({ name, buf }: { name: string; buf: Buffer }) => {
index[name] = Number(buf.readBigUInt64LE())
})
} else {
indexData.forEach(
({ name, offset }: { name: string; offset: number }) => {
Expand Down
Loading

0 comments on commit a1d6055

Please sign in to comment.