@jbrowse/text-indexing 2.15.4 → 2.16.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,13 +3,12 @@ import fetch from 'node-fetch';
3
3
  import { LocalPathLocation, UriLocation, Track } from '../util';
4
4
  export declare function createRemoteStream(urlIn: string): Promise<fetch.Response>;
5
5
  export declare function isURL(FileName: string): boolean;
6
- export declare function getLocalOrRemoteStream(uri: string, out: string): Promise<{
7
- totalBytes: number;
8
- stream: NodeJS.ReadableStream;
9
- } | {
10
- totalBytes: number;
11
- stream: fs.ReadStream;
12
- }>;
6
+ export declare function getLocalOrRemoteStream({ file, out, onBytesReceived, onTotalBytes, }: {
7
+ file: string;
8
+ out: string;
9
+ onBytesReceived: (totalBytesReceived: number) => void;
10
+ onTotalBytes: (totalBytes: number) => void;
11
+ }): Promise<NodeJS.ReadableStream | fs.ReadStream>;
13
12
  export declare function makeLocation(location: string, protocol: string): UriLocation | LocalPathLocation;
14
13
  export declare function guessAdapterFromFileName(filePath: string): Track;
15
14
  /**
@@ -33,20 +33,26 @@ function isURL(FileName) {
33
33
  }
34
34
  return url.protocol === 'http:' || url.protocol === 'https:';
35
35
  }
36
- async function getLocalOrRemoteStream(uri, out) {
37
- if (isURL(uri)) {
38
- const result = await createRemoteStream(uri);
39
- return {
40
- totalBytes: +(result.headers.get('Content-Length') || 0),
41
- stream: result.body,
42
- };
36
+ async function getLocalOrRemoteStream({ file, out, onBytesReceived, onTotalBytes, }) {
37
+ let receivedBytes = 0;
38
+ if (isURL(file)) {
39
+ const result = await createRemoteStream(file);
40
+ result.body.on('data', chunk => {
41
+ receivedBytes += chunk.length;
42
+ onBytesReceived(receivedBytes);
43
+ });
44
+ onTotalBytes(+(result.headers.get('Content-Length') || 0));
45
+ return result.body;
43
46
  }
44
47
  else {
45
- const filename = path_1.default.isAbsolute(uri) ? uri : path_1.default.join(out, uri);
46
- return {
47
- totalBytes: fs_1.default.statSync(filename).size,
48
- stream: fs_1.default.createReadStream(filename),
49
- };
48
+ const filename = path_1.default.isAbsolute(file) ? file : path_1.default.join(out, file);
49
+ const stream = fs_1.default.createReadStream(filename);
50
+ stream.on('data', chunk => {
51
+ receivedBytes += chunk.length;
52
+ onBytesReceived(receivedBytes);
53
+ });
54
+ onTotalBytes(fs_1.default.statSync(filename).size);
55
+ return stream;
50
56
  }
51
57
  }
52
58
  function makeLocation(location, protocol) {
@@ -11,12 +11,11 @@ const util_1 = require("../util");
11
11
  const common_1 = require("./common");
12
12
  async function* indexGff3({ config, attributesToIndex, inLocation, outDir, featureTypesToExclude, onStart, onUpdate, }) {
13
13
  const { trackId } = config;
14
- let receivedBytes = 0;
15
- const { totalBytes, stream } = await (0, common_1.getLocalOrRemoteStream)(inLocation, outDir);
16
- onStart(totalBytes);
17
- stream.on('data', chunk => {
18
- receivedBytes += chunk.length;
19
- onUpdate(receivedBytes);
14
+ const stream = await (0, common_1.getLocalOrRemoteStream)({
15
+ file: inLocation,
16
+ out: outDir,
17
+ onTotalBytes: onStart,
18
+ onBytesReceived: onUpdate,
20
19
  });
21
20
  const rl = readline_1.default.createInterface({
22
21
  input: /.b?gz$/.exec(inLocation) ? stream.pipe((0, zlib_1.createGunzip)()) : stream,
@@ -11,12 +11,11 @@ const util_1 = require("../util");
11
11
  const common_1 = require("./common");
12
12
  async function* indexVcf({ config, attributesToIndex, inLocation, outDir, onStart, onUpdate, }) {
13
13
  const { trackId } = config;
14
- let receivedBytes = 0;
15
- const { totalBytes, stream } = await (0, common_1.getLocalOrRemoteStream)(inLocation, outDir);
16
- onStart(totalBytes);
17
- stream.on('data', chunk => {
18
- receivedBytes += chunk.length;
19
- onUpdate(receivedBytes);
14
+ const stream = await (0, common_1.getLocalOrRemoteStream)({
15
+ file: inLocation,
16
+ out: outDir,
17
+ onTotalBytes: onStart,
18
+ onBytesReceived: onUpdate,
20
19
  });
21
20
  const gzStream = /.b?gz$/.exec(inLocation)
22
21
  ? stream.pipe((0, zlib_1.createGunzip)())
@@ -3,13 +3,12 @@ import fetch from 'node-fetch';
3
3
  import { LocalPathLocation, UriLocation, Track } from '../util';
4
4
  export declare function createRemoteStream(urlIn: string): Promise<fetch.Response>;
5
5
  export declare function isURL(FileName: string): boolean;
6
- export declare function getLocalOrRemoteStream(uri: string, out: string): Promise<{
7
- totalBytes: number;
8
- stream: NodeJS.ReadableStream;
9
- } | {
10
- totalBytes: number;
11
- stream: fs.ReadStream;
12
- }>;
6
+ export declare function getLocalOrRemoteStream({ file, out, onBytesReceived, onTotalBytes, }: {
7
+ file: string;
8
+ out: string;
9
+ onBytesReceived: (totalBytesReceived: number) => void;
10
+ onTotalBytes: (totalBytes: number) => void;
11
+ }): Promise<NodeJS.ReadableStream | fs.ReadStream>;
13
12
  export declare function makeLocation(location: string, protocol: string): UriLocation | LocalPathLocation;
14
13
  export declare function guessAdapterFromFileName(filePath: string): Track;
15
14
  /**
@@ -22,20 +22,26 @@ export function isURL(FileName) {
22
22
  }
23
23
  return url.protocol === 'http:' || url.protocol === 'https:';
24
24
  }
25
- export async function getLocalOrRemoteStream(uri, out) {
26
- if (isURL(uri)) {
27
- const result = await createRemoteStream(uri);
28
- return {
29
- totalBytes: +(result.headers.get('Content-Length') || 0),
30
- stream: result.body,
31
- };
25
+ export async function getLocalOrRemoteStream({ file, out, onBytesReceived, onTotalBytes, }) {
26
+ let receivedBytes = 0;
27
+ if (isURL(file)) {
28
+ const result = await createRemoteStream(file);
29
+ result.body.on('data', chunk => {
30
+ receivedBytes += chunk.length;
31
+ onBytesReceived(receivedBytes);
32
+ });
33
+ onTotalBytes(+(result.headers.get('Content-Length') || 0));
34
+ return result.body;
32
35
  }
33
36
  else {
34
- const filename = path.isAbsolute(uri) ? uri : path.join(out, uri);
35
- return {
36
- totalBytes: fs.statSync(filename).size,
37
- stream: fs.createReadStream(filename),
38
- };
37
+ const filename = path.isAbsolute(file) ? file : path.join(out, file);
38
+ const stream = fs.createReadStream(filename);
39
+ stream.on('data', chunk => {
40
+ receivedBytes += chunk.length;
41
+ onBytesReceived(receivedBytes);
42
+ });
43
+ onTotalBytes(fs.statSync(filename).size);
44
+ return stream;
39
45
  }
40
46
  }
41
47
  export function makeLocation(location, protocol) {
@@ -5,12 +5,11 @@ import { decodeURIComponentNoThrow } from '../util';
5
5
  import { getLocalOrRemoteStream } from './common';
6
6
  export async function* indexGff3({ config, attributesToIndex, inLocation, outDir, featureTypesToExclude, onStart, onUpdate, }) {
7
7
  const { trackId } = config;
8
- let receivedBytes = 0;
9
- const { totalBytes, stream } = await getLocalOrRemoteStream(inLocation, outDir);
10
- onStart(totalBytes);
11
- stream.on('data', chunk => {
12
- receivedBytes += chunk.length;
13
- onUpdate(receivedBytes);
8
+ const stream = await getLocalOrRemoteStream({
9
+ file: inLocation,
10
+ out: outDir,
11
+ onTotalBytes: onStart,
12
+ onBytesReceived: onUpdate,
14
13
  });
15
14
  const rl = readline.createInterface({
16
15
  input: /.b?gz$/.exec(inLocation) ? stream.pipe(createGunzip()) : stream,
@@ -5,12 +5,11 @@ import { decodeURIComponentNoThrow } from '../util';
5
5
  import { getLocalOrRemoteStream } from './common';
6
6
  export async function* indexVcf({ config, attributesToIndex, inLocation, outDir, onStart, onUpdate, }) {
7
7
  const { trackId } = config;
8
- let receivedBytes = 0;
9
- const { totalBytes, stream } = await getLocalOrRemoteStream(inLocation, outDir);
10
- onStart(totalBytes);
11
- stream.on('data', chunk => {
12
- receivedBytes += chunk.length;
13
- onUpdate(receivedBytes);
8
+ const stream = await getLocalOrRemoteStream({
9
+ file: inLocation,
10
+ out: outDir,
11
+ onTotalBytes: onStart,
12
+ onBytesReceived: onUpdate,
14
13
  });
15
14
  const gzStream = /.b?gz$/.exec(inLocation)
16
15
  ? stream.pipe(createGunzip())
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jbrowse/text-indexing",
3
- "version": "2.15.4",
3
+ "version": "2.16.1",
4
4
  "description": "JBrowse 2 text indexing for desktop",
5
5
  "keywords": [
6
6
  "jbrowse",
@@ -42,7 +42,7 @@
42
42
  },
43
43
  "dependencies": {
44
44
  "@babel/runtime": "^7.16.3",
45
- "@jbrowse/core": "^2.15.4",
45
+ "@jbrowse/core": "^2.16.1",
46
46
  "ixixx": "^2.0.1",
47
47
  "node-fetch": "^2.6.0",
48
48
  "sanitize-filename": "^1.6.3"
@@ -58,5 +58,5 @@
58
58
  "publishConfig": {
59
59
  "access": "public"
60
60
  },
61
- "gitHead": "686b4ad9016b3586e8230180f7adb44c238ba4fb"
61
+ "gitHead": "c6a658d2344989895543f0456b1cf7dd3b937769"
62
62
  }