Skip to content

Commit

Permalink
Remove usage of url module
Browse files Browse the repository at this point in the history
  • Loading branch information
cmdcolin committed Mar 18, 2024
1 parent 9021a23 commit 3524f3c
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 27 deletions.
2 changes: 1 addition & 1 deletion example/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,6 @@
</head>
<body>
<h1>Hello world</h1>
<pre id="output"></div>
<div id="output" />
</body>
</html>
14 changes: 2 additions & 12 deletions src/io/index.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,6 @@
import url from 'url'
import { ensureNotNullish } from '../typescript'
import { Filehandle } from '../cramFile/filehandle'
import { LocalFile, RemoteFile } from 'generic-filehandle'

function fromUrl(source: string) {
const { protocol, pathname } = url.parse(source)
if (protocol === 'file:') {
return new LocalFile(unescape(ensureNotNullish(pathname)))
}
return new RemoteFile(source)
}

function open(
maybeUrl?: string,
maybePath?: string,
Expand All @@ -20,14 +10,14 @@ function open(
return maybeFilehandle
}
if (maybeUrl) {
return fromUrl(maybeUrl)
return new RemoteFile(maybeUrl)
}
if (maybePath) {
return new LocalFile(maybePath)
}
throw new Error('no url, path, or filehandle provided, cannot open')
}

export { fromUrl, open }
export { open }

export { LocalFile, RemoteFile } from 'generic-filehandle'
7 changes: 0 additions & 7 deletions src/typescript.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
export function ensureNotNullish<T>(x: T | null | undefined): T {
if (x === null || x === undefined) {
throw new Error('Value must not be nullish.')
}
return x
}

export type TupleOf<T, N extends number> = N extends N
? number extends N
? T[]
Expand Down
2 changes: 1 addition & 1 deletion test/indexedfile.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ test('region not downloading enough records', async () => {
// entries
const index = new CraiIndex({
filehandle: testDataFile(
'HG002_ONTrel2_16x_RG_HP10xtrioRTG.chr1.cram.crai ',
'HG002_ONTrel2_16x_RG_HP10xtrioRTG.chr1.cram.crai',
),
})
const entries = await index.getEntriesForRange(0, 75100635, 75125544)
Expand Down
13 changes: 7 additions & 6 deletions test/lib/util.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { fromUrl } from '../../src/io'
import path from 'path'
import { LocalFile } from 'generic-filehandle'

const dataDir = path.dirname(require.resolve('../data/xx.fa'))

export function testDataUrl(filename: string) {
return `file://${dataDir}/${filename}`.replace('#', '%23')
}
// export function testDataUrl(filename: string) {
// return
// }

export function testDataFile(filename: string) {
const source = testDataUrl(filename)
return fromUrl(source)
// console.log({ filename })
// const source = testDataUrl(filename)
return new LocalFile(`${dataDir}/${filename}`)
}

0 comments on commit 3524f3c

Please sign in to comment.