Skip to content

Commit

Permalink
Lazy load alternative methods
Browse files Browse the repository at this point in the history
  • Loading branch information
cmdcolin committed Nov 12, 2023
1 parent 8db6cac commit 93754a8
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 20,834 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ on: push

jobs:
test:
name: Lint, build, and test on node 16.x and ubuntu-latest
name: Lint, build, and test on node 20.x and ubuntu-latest
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Use Node.js 16.x
- name: Use Node.js 20.x
uses: actions/setup-node@v3
with:
node-version: 16.x
node-version: 20.x
- name: Install deps (with cache)
uses: bahmutov/npm-install@v1
- name: Lint codebase
Expand Down
17 changes: 3 additions & 14 deletions src/cramFile/file.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import { unzip } from '../unzip'
import crc32 from 'buffer-crc32'
import QuickLRU from 'quick-lru'
// @ts-expect-error
import bzip2 from 'bzip2'
import { XzReadableStream } from 'xz-decompress'
import htscodecs from '@jkbonfield/htscodecs'
import { Parser } from '@gmod/binary-parser'

Expand Down Expand Up @@ -110,17 +107,6 @@ export default class CramFile {
}
}

// toString() {
// if (this.file.filename) {
// return this.file.filename
// }
// if (this.file.url) {
// return this.file.url
// }
//
// return '(cram file)'
// }

// can just read this object like a filehandle
read(
buffer: Buffer,
Expand Down Expand Up @@ -338,6 +324,8 @@ export default class CramFile {
const result = unzip(inputBuffer)
result.copy(outputBuffer)
} else if (compressionMethod === 'bzip2') {
// @ts-expect-error
const bzip2 = await import('bzip2')
const bits = bzip2.array(inputBuffer)
let size = bzip2.header(bits)
let j = 0
Expand All @@ -351,6 +339,7 @@ export default class CramFile {
}
} while (chunk != -1)
} else if (compressionMethod === 'lzma') {
const { XzReadableStream } = await import('xz-decompress')

Check failure on line 342 in src/cramFile/file.ts

View workflow job for this annotation

GitHub Actions / Lint, build, and test on node 20.x and ubuntu-latest

Dynamic imports are only supported when the '--module' flag is set to 'es2020', 'es2022', 'esnext', 'commonjs', 'amd', 'system', 'umd', 'node16', or 'nodenext'.
const decompressedResponse = new Response(
new XzReadableStream(bufferToStream(inputBuffer)),
)
Expand Down
4 changes: 2 additions & 2 deletions test/compressions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { CramFile } from '../src/index'
import { FetchableSmallFasta } from './lib/fasta'

test('lzma', async () => {
const fasta = new FetchableSmallFasta(testDataFile('hts-specs/ce.fa'))
const fasta = new FetchableSmallFasta(testDataFile('ce.fa'))
const seqFetch = fasta.fetch.bind(fasta)
const file = new CramFile({
filehandle: testDataFile('hts-specs/0903_comp_lzma.cram'),
Expand All @@ -18,7 +18,7 @@ test('lzma', async () => {
})

test('bzip2', async () => {
const fasta = new FetchableSmallFasta(testDataFile('hts-specs/ce.fa'))
const fasta = new FetchableSmallFasta(testDataFile('ce.fa'))
const seqFetch = fasta.fetch.bind(fasta)
const file = new CramFile({
filehandle: testDataFile('hts-specs/0902_comp_bz2.cram'),
Expand Down
Loading

0 comments on commit 93754a8

Please sign in to comment.