@loaders.gl/core 3.4.0-alpha.3 → 3.4.0-alpha.5
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.
- package/dist/dist.min.js +127 -97
- package/dist/es5/iterators/batch-iterators/timed-batch-iterator.js.map +1 -1
- package/dist/es5/iterators/make-iterator/make-blob-iterator.js.map +1 -1
- package/dist/es5/iterators/make-iterator/make-stream-iterator.js.map +1 -1
- package/dist/es5/iterators/make-iterator/make-string-iterator.js.map +1 -1
- package/dist/es5/iterators/make-stream/make-dom-stream.js.map +1 -1
- package/dist/es5/iterators/make-stream/make-node-stream.js.map +1 -1
- package/dist/es5/lib/api/encode.js.map +1 -1
- package/dist/es5/lib/api/parse-in-batches.js +15 -14
- package/dist/es5/lib/api/parse-in-batches.js.map +1 -1
- package/dist/es5/lib/api/parse-sync.js +3 -4
- package/dist/es5/lib/api/parse-sync.js.map +1 -1
- package/dist/es5/lib/api/parse.js +3 -3
- package/dist/es5/lib/api/parse.js.map +1 -1
- package/dist/es5/lib/api/register-loaders.js.map +1 -1
- package/dist/es5/lib/api/select-loader.js +6 -7
- package/dist/es5/lib/api/select-loader.js.map +1 -1
- package/dist/es5/lib/fetch/fetch-error-message.js.map +1 -1
- package/dist/es5/lib/fetch/read-array-buffer.js.map +1 -1
- package/dist/es5/lib/filesystems/browser-filesystem.js.map +1 -1
- package/dist/es5/lib/filesystems/read-array-buffer.js.map +1 -1
- package/dist/es5/lib/init.js +1 -1
- package/dist/es5/lib/init.js.map +1 -1
- package/dist/es5/lib/loader-utils/check-errors.js.map +1 -1
- package/dist/es5/lib/loader-utils/get-data.js.map +1 -1
- package/dist/es5/lib/loader-utils/get-fetch-function.js.map +1 -1
- package/dist/es5/lib/loader-utils/loader-context.js +16 -8
- package/dist/es5/lib/loader-utils/loader-context.js.map +1 -1
- package/dist/es5/lib/loader-utils/option-defaults.js.map +1 -1
- package/dist/es5/lib/loader-utils/option-utils.js.map +1 -1
- package/dist/es5/lib/progress/fetch-progress.js.map +1 -1
- package/dist/es5/lib/utils/resource-utils.js +31 -27
- package/dist/es5/lib/utils/resource-utils.js.map +1 -1
- package/dist/es5/lib/utils/response-utils.js +6 -5
- package/dist/es5/lib/utils/response-utils.js.map +1 -1
- package/dist/es5/lib/utils/url-utils.js +16 -0
- package/dist/es5/lib/utils/url-utils.js.map +1 -0
- package/dist/es5/null-loader.js +1 -1
- package/dist/esm/iterators/batch-iterators/timed-batch-iterator.js.map +1 -1
- package/dist/esm/iterators/make-iterator/make-blob-iterator.js.map +1 -1
- package/dist/esm/iterators/make-iterator/make-stream-iterator.js.map +1 -1
- package/dist/esm/iterators/make-iterator/make-string-iterator.js.map +1 -1
- package/dist/esm/iterators/make-stream/make-dom-stream.js.map +1 -1
- package/dist/esm/iterators/make-stream/make-node-stream.js.map +1 -1
- package/dist/esm/lib/api/encode.js.map +1 -1
- package/dist/esm/lib/api/parse-in-batches.js +6 -7
- package/dist/esm/lib/api/parse-in-batches.js.map +1 -1
- package/dist/esm/lib/api/parse-sync.js +4 -6
- package/dist/esm/lib/api/parse-sync.js.map +1 -1
- package/dist/esm/lib/api/parse.js +3 -5
- package/dist/esm/lib/api/parse.js.map +1 -1
- package/dist/esm/lib/api/register-loaders.js.map +1 -1
- package/dist/esm/lib/api/select-loader.js +7 -10
- package/dist/esm/lib/api/select-loader.js.map +1 -1
- package/dist/esm/lib/fetch/fetch-error-message.js.map +1 -1
- package/dist/esm/lib/fetch/read-array-buffer.js.map +1 -1
- package/dist/esm/lib/filesystems/browser-filesystem.js.map +1 -1
- package/dist/esm/lib/filesystems/read-array-buffer.js.map +1 -1
- package/dist/esm/lib/init.js +1 -1
- package/dist/esm/lib/init.js.map +1 -1
- package/dist/esm/lib/loader-utils/check-errors.js.map +1 -1
- package/dist/esm/lib/loader-utils/get-data.js.map +1 -1
- package/dist/esm/lib/loader-utils/get-fetch-function.js.map +1 -1
- package/dist/esm/lib/loader-utils/loader-context.js +16 -8
- package/dist/esm/lib/loader-utils/loader-context.js.map +1 -1
- package/dist/esm/lib/loader-utils/option-defaults.js.map +1 -1
- package/dist/esm/lib/loader-utils/option-utils.js.map +1 -1
- package/dist/esm/lib/progress/fetch-progress.js.map +1 -1
- package/dist/esm/lib/utils/resource-utils.js +29 -26
- package/dist/esm/lib/utils/resource-utils.js.map +1 -1
- package/dist/esm/lib/utils/response-utils.js +3 -5
- package/dist/esm/lib/utils/response-utils.js.map +1 -1
- package/dist/esm/lib/utils/url-utils.js +9 -0
- package/dist/esm/lib/utils/url-utils.js.map +1 -0
- package/dist/esm/null-loader.js +1 -1
- package/dist/lib/api/parse-in-batches.d.ts.map +1 -1
- package/dist/lib/api/parse-in-batches.js +4 -7
- package/dist/lib/api/parse-sync.d.ts.map +1 -1
- package/dist/lib/api/parse-sync.js +3 -3
- package/dist/lib/api/parse.js +2 -2
- package/dist/lib/api/select-loader.d.ts.map +1 -1
- package/dist/lib/api/select-loader.js +6 -3
- package/dist/lib/loader-utils/loader-context.d.ts +1 -1
- package/dist/lib/loader-utils/loader-context.d.ts.map +1 -1
- package/dist/lib/loader-utils/loader-context.js +17 -7
- package/dist/lib/utils/resource-utils.d.ts +17 -8
- package/dist/lib/utils/resource-utils.d.ts.map +1 -1
- package/dist/lib/utils/resource-utils.js +46 -34
- package/dist/lib/utils/response-utils.d.ts.map +1 -1
- package/dist/lib/utils/response-utils.js +2 -1
- package/dist/lib/utils/url-utils.d.ts +3 -0
- package/dist/lib/utils/url-utils.d.ts.map +1 -0
- package/dist/lib/utils/url-utils.js +14 -0
- package/dist/null-worker.js +1 -1
- package/package.json +4 -4
- package/src/lib/api/parse-in-batches.ts +8 -9
- package/src/lib/api/parse-sync.ts +8 -4
- package/src/lib/api/parse.ts +3 -3
- package/src/lib/api/select-loader.ts +7 -4
- package/src/lib/loader-utils/loader-context.ts +19 -8
- package/src/lib/utils/resource-utils.ts +54 -34
- package/src/lib/utils/response-utils.ts +3 -2
- package/src/lib/utils/url-utils.ts +12 -0
|
@@ -11,7 +11,7 @@ import {isLoaderObject} from '../loader-utils/normalize-loader';
|
|
|
11
11
|
import {normalizeOptions} from '../loader-utils/option-utils';
|
|
12
12
|
import {getLoaderContext} from '../loader-utils/loader-context';
|
|
13
13
|
import {getAsyncIterableFromData} from '../loader-utils/get-data';
|
|
14
|
-
import {
|
|
14
|
+
import {getResourceUrl} from '../utils/resource-utils';
|
|
15
15
|
import {selectLoader} from './select-loader';
|
|
16
16
|
|
|
17
17
|
// Ensure `parse` is available in context if loader falls back to `parse`
|
|
@@ -32,6 +32,8 @@ export async function parseInBatches(
|
|
|
32
32
|
): Promise<AsyncIterable<any>> {
|
|
33
33
|
assert(!context || typeof context === 'object'); // parseInBatches no longer accepts final url
|
|
34
34
|
|
|
35
|
+
const loaderArray = Array.isArray(loaders) ? loaders : undefined;
|
|
36
|
+
|
|
35
37
|
// Signature: parseInBatches(data, options, url) - Uses registered loaders
|
|
36
38
|
if (!Array.isArray(loaders) && !isLoaderObject(loaders)) {
|
|
37
39
|
context = undefined; // context not supported in short signature
|
|
@@ -43,11 +45,11 @@ export async function parseInBatches(
|
|
|
43
45
|
options = options || {};
|
|
44
46
|
|
|
45
47
|
// Extract a url for auto detection
|
|
46
|
-
const
|
|
48
|
+
const url = getResourceUrl(data);
|
|
47
49
|
|
|
48
50
|
// Chooses a loader and normalizes it
|
|
49
51
|
// Note - only uses URL and contentType for streams and iterator inputs
|
|
50
|
-
const loader = await selectLoader(data as ArrayBuffer, loaders as Loader[], options);
|
|
52
|
+
const loader = await selectLoader(data as ArrayBuffer, loaders as Loader | Loader[], options);
|
|
51
53
|
// Note: if options.nothrow was set, it is possible that no loader was found, if so just return null
|
|
52
54
|
if (!loader) {
|
|
53
55
|
// @ts-ignore
|
|
@@ -55,14 +57,11 @@ export async function parseInBatches(
|
|
|
55
57
|
}
|
|
56
58
|
|
|
57
59
|
// Normalize options
|
|
58
|
-
|
|
59
|
-
options = normalizeOptions(options, loader, loaders, url);
|
|
60
|
-
// @ts-ignore
|
|
60
|
+
options = normalizeOptions(options, loader, loaderArray, url);
|
|
61
61
|
context = getLoaderContext(
|
|
62
|
-
|
|
63
|
-
{url, parseInBatches, parse, loaders: loaders as Loader[]},
|
|
62
|
+
{url, parseInBatches, parse, loaders: loaderArray},
|
|
64
63
|
options,
|
|
65
|
-
context
|
|
64
|
+
context || null
|
|
66
65
|
);
|
|
67
66
|
|
|
68
67
|
return await parseWithLoaderInBatches(loader as LoaderWithParser, data, options, context);
|
|
@@ -11,7 +11,7 @@ import {isLoaderObject} from '../loader-utils/normalize-loader';
|
|
|
11
11
|
import {normalizeOptions} from '../loader-utils/option-utils';
|
|
12
12
|
import {getArrayBufferOrStringFromDataSync} from '../loader-utils/get-data';
|
|
13
13
|
import {getLoaderContext, getLoadersFromContext} from '../loader-utils/loader-context';
|
|
14
|
-
import {
|
|
14
|
+
import {getResourceUrl} from '../utils/resource-utils';
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
17
|
* Parses `data` synchronously using a specified loader
|
|
@@ -52,12 +52,16 @@ export function parseSync(
|
|
|
52
52
|
options = normalizeOptions(options, loader, candidateLoaders);
|
|
53
53
|
|
|
54
54
|
// Extract a url for auto detection
|
|
55
|
-
const
|
|
55
|
+
const url = getResourceUrl(data);
|
|
56
56
|
|
|
57
57
|
const parse = () => {
|
|
58
|
-
throw new Error('parseSync called parse');
|
|
58
|
+
throw new Error('parseSync called parse (which is async');
|
|
59
59
|
};
|
|
60
|
-
context = getLoaderContext(
|
|
60
|
+
context = getLoaderContext(
|
|
61
|
+
{url, parseSync, parse, loaders: loaders as Loader[]},
|
|
62
|
+
options,
|
|
63
|
+
context || null
|
|
64
|
+
);
|
|
61
65
|
|
|
62
66
|
return parseWithLoaderSync(loader as LoaderWithParser, data, options, context);
|
|
63
67
|
}
|
package/src/lib/api/parse.ts
CHANGED
|
@@ -6,7 +6,7 @@ import {isResponse} from '../../javascript-utils/is-type';
|
|
|
6
6
|
import {normalizeOptions} from '../loader-utils/option-utils';
|
|
7
7
|
import {getArrayBufferOrStringFromData} from '../loader-utils/get-data';
|
|
8
8
|
import {getLoaderContext, getLoadersFromContext} from '../loader-utils/loader-context';
|
|
9
|
-
import {
|
|
9
|
+
import {getResourceUrl} from '../utils/resource-utils';
|
|
10
10
|
import {selectLoader} from './select-loader';
|
|
11
11
|
|
|
12
12
|
/**
|
|
@@ -36,7 +36,7 @@ export async function parse(
|
|
|
36
36
|
options = options || {};
|
|
37
37
|
|
|
38
38
|
// Extract a url for auto detection
|
|
39
|
-
const
|
|
39
|
+
const url = getResourceUrl(data);
|
|
40
40
|
|
|
41
41
|
// Chooses a loader (and normalizes it)
|
|
42
42
|
// Also use any loaders in the context, new loaders take priority
|
|
@@ -53,7 +53,7 @@ export async function parse(
|
|
|
53
53
|
options = normalizeOptions(options, loader, candidateLoaders, url);
|
|
54
54
|
|
|
55
55
|
// Get a context (if already present, will be unchanged)
|
|
56
|
-
context = getLoaderContext({url, parse, loaders: candidateLoaders}, options, context);
|
|
56
|
+
context = getLoaderContext({url, parse, loaders: candidateLoaders}, options, context || null);
|
|
57
57
|
|
|
58
58
|
return await parseWithLoader(loader, data, options, context);
|
|
59
59
|
}
|
|
@@ -2,9 +2,10 @@ import type {LoaderContext, LoaderOptions, Loader} from '@loaders.gl/loader-util
|
|
|
2
2
|
import {compareArrayBuffers, path} from '@loaders.gl/loader-utils';
|
|
3
3
|
import {normalizeLoader} from '../loader-utils/normalize-loader';
|
|
4
4
|
import {log} from '../utils/log';
|
|
5
|
-
import {
|
|
5
|
+
import {getResourceUrl, getResourceMIMEType} from '../utils/resource-utils';
|
|
6
6
|
import {getRegisteredLoaders} from './register-loaders';
|
|
7
7
|
import {isBlob} from '../../javascript-utils/is-type';
|
|
8
|
+
import {stripQueryString} from '../utils/url-utils';
|
|
8
9
|
|
|
9
10
|
const EXT_PATTERN = /\.([^.]+)$/;
|
|
10
11
|
|
|
@@ -111,9 +112,10 @@ function selectLoaderInternal(
|
|
|
111
112
|
options?: LoaderOptions,
|
|
112
113
|
context?: LoaderContext
|
|
113
114
|
) {
|
|
114
|
-
const
|
|
115
|
+
const url = getResourceUrl(data);
|
|
116
|
+
const type = getResourceMIMEType(data);
|
|
115
117
|
|
|
116
|
-
const testUrl = url || context?.url;
|
|
118
|
+
const testUrl = stripQueryString(url) || context?.url;
|
|
117
119
|
|
|
118
120
|
let loader: Loader | null = null;
|
|
119
121
|
let reason: string = '';
|
|
@@ -161,7 +163,8 @@ function validHTTPResponse(data: any): boolean {
|
|
|
161
163
|
|
|
162
164
|
/** Generate a helpful message to help explain why loader selection failed. */
|
|
163
165
|
function getNoValidLoaderMessage(data): string {
|
|
164
|
-
const
|
|
166
|
+
const url = getResourceUrl(data);
|
|
167
|
+
const type = getResourceMIMEType(data);
|
|
165
168
|
|
|
166
169
|
let message = 'No valid loader found (';
|
|
167
170
|
message += url ? `${path.filename(url)}, ` : 'no url provided, ';
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import type {Loader, LoaderOptions, LoaderContext} from '@loaders.gl/loader-utils';
|
|
2
2
|
import {getFetchFunction} from './get-fetch-function';
|
|
3
|
+
import {extractQueryString, stripQueryString} from '../utils/url-utils';
|
|
4
|
+
import {path} from '@loaders.gl/loader-utils';
|
|
3
5
|
|
|
4
6
|
/**
|
|
5
7
|
* "sub" loaders invoked by other loaders get a "context" injected on `this`
|
|
@@ -12,26 +14,35 @@ import {getFetchFunction} from './get-fetch-function';
|
|
|
12
14
|
*/
|
|
13
15
|
export function getLoaderContext(
|
|
14
16
|
context: Omit<LoaderContext, 'fetch'> & Partial<Pick<LoaderContext, 'fetch'>>,
|
|
15
|
-
options
|
|
16
|
-
|
|
17
|
+
options: LoaderOptions,
|
|
18
|
+
parentContext: LoaderContext | null
|
|
17
19
|
): LoaderContext {
|
|
18
20
|
// For recursive calls, we already have a context
|
|
19
21
|
// TODO - add any additional loaders to context?
|
|
20
|
-
if (
|
|
21
|
-
return
|
|
22
|
+
if (parentContext) {
|
|
23
|
+
return parentContext;
|
|
22
24
|
}
|
|
23
25
|
|
|
24
|
-
const
|
|
26
|
+
const newContext: LoaderContext = {
|
|
25
27
|
fetch: getFetchFunction(options, context),
|
|
26
28
|
...context
|
|
27
29
|
};
|
|
28
30
|
|
|
31
|
+
// Parse URLs so that subloaders can easily generate correct strings
|
|
32
|
+
if (newContext.url) {
|
|
33
|
+
const baseUrl = stripQueryString(newContext.url);
|
|
34
|
+
newContext.baseUrl = baseUrl;
|
|
35
|
+
newContext.queryString = extractQueryString(newContext.url);
|
|
36
|
+
newContext.filename = path.filename(baseUrl);
|
|
37
|
+
newContext.baseUrl = path.dirname(baseUrl);
|
|
38
|
+
}
|
|
39
|
+
|
|
29
40
|
// Recursive loading does not use single loader
|
|
30
|
-
if (!Array.isArray(
|
|
31
|
-
|
|
41
|
+
if (!Array.isArray(newContext.loaders)) {
|
|
42
|
+
newContext.loaders = null;
|
|
32
43
|
}
|
|
33
44
|
|
|
34
|
-
return
|
|
45
|
+
return newContext;
|
|
35
46
|
}
|
|
36
47
|
|
|
37
48
|
// eslint-disable-next-line complexity
|
|
@@ -1,51 +1,73 @@
|
|
|
1
|
+
// loaders.gl, MIT license
|
|
2
|
+
|
|
1
3
|
import {isResponse, isBlob} from '../../javascript-utils/is-type';
|
|
2
4
|
import {parseMIMEType, parseMIMETypeFromURL} from './mime-type-utils';
|
|
5
|
+
import {stripQueryString} from './url-utils';
|
|
3
6
|
|
|
4
|
-
|
|
7
|
+
/**
|
|
8
|
+
* A loadable resource. Includes:
|
|
9
|
+
* `Response`, `Blob` (`File` is a subclass), string URLs and data URLs
|
|
10
|
+
*/
|
|
11
|
+
export type Resource = Response | Blob | string;
|
|
5
12
|
|
|
6
13
|
/**
|
|
7
|
-
* Returns
|
|
8
|
-
*
|
|
14
|
+
* Returns the URL associated with this resource.
|
|
15
|
+
* The returned value may include a query string and need further processing.
|
|
16
|
+
* If it cannot determine url, the corresponding value will be an empty string
|
|
9
17
|
*
|
|
10
|
-
* @
|
|
18
|
+
* @todo string parameters are assumed to be URLs
|
|
19
|
+
*/
|
|
20
|
+
export function getResourceUrl(resource: unknown): string {
|
|
21
|
+
// If resource is a `Response`, it contains the information directly as a field
|
|
22
|
+
if (isResponse(resource)) {
|
|
23
|
+
const response = resource as Response;
|
|
24
|
+
return response.url;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// If the resource is a Blob or a File (subclass of Blob)
|
|
28
|
+
if (isBlob(resource)) {
|
|
29
|
+
const blob = resource as Blob;
|
|
30
|
+
// File objects have a "name" property. Blob objects don't have any
|
|
31
|
+
// url (name) information
|
|
32
|
+
return blob.name || '';
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (typeof resource === 'string') {
|
|
36
|
+
return resource;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// Unknown
|
|
40
|
+
return '';
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Returns the URL associated with this resource.
|
|
45
|
+
* The returned value may include a query string and need further processing.
|
|
46
|
+
* If it cannot determine url, the corresponding value will be an empty string
|
|
11
47
|
*
|
|
12
48
|
* @todo string parameters are assumed to be URLs
|
|
13
49
|
*/
|
|
14
|
-
export function
|
|
50
|
+
export function getResourceMIMEType(resource: unknown): string {
|
|
15
51
|
// If resource is a response, it contains the information directly
|
|
16
52
|
if (isResponse(resource)) {
|
|
17
|
-
const
|
|
18
|
-
const contentTypeHeader =
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
type: parseMIMEType(contentTypeHeader) || parseMIMETypeFromURL(url)
|
|
22
|
-
};
|
|
53
|
+
const response = resource as Response;
|
|
54
|
+
const contentTypeHeader = response.headers.get('content-type') || '';
|
|
55
|
+
const noQueryUrl = stripQueryString(response.url);
|
|
56
|
+
return parseMIMEType(contentTypeHeader) || parseMIMETypeFromURL(noQueryUrl);
|
|
23
57
|
}
|
|
24
58
|
|
|
25
59
|
// If the resource is a Blob or a File (subclass of Blob)
|
|
26
60
|
if (isBlob(resource)) {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
// url (name) information
|
|
30
|
-
url: stripQueryString(resource.name || ''),
|
|
31
|
-
type: resource.type || ''
|
|
32
|
-
};
|
|
61
|
+
const blob = resource as Blob;
|
|
62
|
+
return blob.type || '';
|
|
33
63
|
}
|
|
34
64
|
|
|
35
65
|
if (typeof resource === 'string') {
|
|
36
|
-
return
|
|
37
|
-
// TODO this could mess up data URL but it doesn't matter as it is just used for inference
|
|
38
|
-
url: stripQueryString(resource),
|
|
39
|
-
// If a data url
|
|
40
|
-
type: parseMIMETypeFromURL(resource)
|
|
41
|
-
};
|
|
66
|
+
return parseMIMETypeFromURL(resource);
|
|
42
67
|
}
|
|
43
68
|
|
|
44
69
|
// Unknown
|
|
45
|
-
return
|
|
46
|
-
url: '',
|
|
47
|
-
type: ''
|
|
48
|
-
};
|
|
70
|
+
return '';
|
|
49
71
|
}
|
|
50
72
|
|
|
51
73
|
/**
|
|
@@ -55,12 +77,14 @@ export function getResourceUrlAndType(resource: any): {url: string; type: string
|
|
|
55
77
|
|
|
56
78
|
* @note string parameters are NOT assumed to be URLs
|
|
57
79
|
*/
|
|
58
|
-
export function getResourceContentLength(resource:
|
|
80
|
+
export function getResourceContentLength(resource: unknown): number {
|
|
59
81
|
if (isResponse(resource)) {
|
|
60
|
-
|
|
82
|
+
const response = resource as Response;
|
|
83
|
+
return response.headers['content-length'] || -1;
|
|
61
84
|
}
|
|
62
85
|
if (isBlob(resource)) {
|
|
63
|
-
|
|
86
|
+
const blob = resource as Blob;
|
|
87
|
+
return blob.size;
|
|
64
88
|
}
|
|
65
89
|
if (typeof resource === 'string') {
|
|
66
90
|
// TODO - handle data URL?
|
|
@@ -74,7 +98,3 @@ export function getResourceContentLength(resource: any): number {
|
|
|
74
98
|
}
|
|
75
99
|
return -1;
|
|
76
100
|
}
|
|
77
|
-
|
|
78
|
-
function stripQueryString(url) {
|
|
79
|
-
return url.replace(QUERY_STRING_PATTERN, '');
|
|
80
|
-
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {isResponse} from '../../javascript-utils/is-type';
|
|
2
|
-
import {getResourceContentLength,
|
|
2
|
+
import {getResourceContentLength, getResourceUrl, getResourceMIMEType} from './resource-utils';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Returns a Response object
|
|
@@ -22,7 +22,8 @@ export async function makeResponse(resource: any): Promise<Response> {
|
|
|
22
22
|
|
|
23
23
|
// `new Response(File)` does not preserve content-type and URL
|
|
24
24
|
// so we add them here
|
|
25
|
-
const
|
|
25
|
+
const url = getResourceUrl(resource);
|
|
26
|
+
const type = getResourceMIMEType(resource);
|
|
26
27
|
if (type) {
|
|
27
28
|
headers['content-type'] = type;
|
|
28
29
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// loaders.gl, MIT license
|
|
2
|
+
|
|
3
|
+
const QUERY_STRING_PATTERN = /\?.*/;
|
|
4
|
+
|
|
5
|
+
export function extractQueryString(url): string {
|
|
6
|
+
const matches = url.match(QUERY_STRING_PATTERN);
|
|
7
|
+
return matches && matches[0];
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function stripQueryString(url): string {
|
|
11
|
+
return url.replace(QUERY_STRING_PATTERN, '');
|
|
12
|
+
}
|