Skip to content

Commit 2277172

Browse files
committed
Make it possible to build a RemoteSource with a user-provided client
1 parent f15d770 commit 2277172

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/geotiff.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ import DataView64 from './dataview64.js';
44
import DataSlice from './dataslice.js';
55
import Pool from './pool.js';
66

7-
import { makeRemoteSource } from './source/remote.js';
7+
import { makeRemoteSource, makeCustomSource } from './source/remote.js';
88
import { makeBufferSource } from './source/arraybuffer.js';
99
import { makeFileReaderSource } from './source/filereader.js';
1010
import { makeFileSource } from './source/file.js';
11+
import { BaseClient, BaseResponse } from './source/client/base.js';
1112

1213
import { fieldTypes, fieldTagNames, arrayFields, geoKeyNames } from './globals.js';
1314
import { writeGeotiff } from './geotiffwriter.js';
@@ -684,6 +685,19 @@ export async function fromUrl(url, options = {}, signal) {
684685
return GeoTIFF.fromSource(makeRemoteSource(url, options), signal);
685686
}
686687

688+
/**
689+
* Creates a new GeoTIFF from a custom {@link BaseClient}.
690+
* @param {BaseClient} client The client.
691+
* @param {object} [options] Additional options to pass to the source.
692+
* See {@link makeRemoteSource} for details.
693+
* @param {AbortSignal} [signal] An AbortSignal that may be signalled if the request is
694+
* to be aborted
695+
* @returns {Promise<GeoTIFF>} The resulting GeoTIFF file.
696+
*/
697+
export async function fromCustomClient(client, options = {}, signal) {
698+
return GeoTIFF.fromSource(makeCustomSource(client, options), signal);
699+
}
700+
687701
/**
688702
* Construct a new GeoTIFF from an
689703
* [ArrayBuffer]{@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer}.
@@ -757,3 +771,4 @@ export function writeArrayBuffer(values, metadata) {
757771

758772
export { Pool };
759773
export { GeoTIFFImage };
774+
export { BaseClient, BaseResponse };

src/source/remote.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,11 @@ export function makeHttpSource(url, { headers = {}, maxRanges = 0, allowFullFile
175175
return maybeWrapInBlockedSource(source, blockOptions);
176176
}
177177

178+
export function makeCustomSource(client, { headers = {}, maxRanges = 0, allowFullFile = false, ...blockOptions } = {}) {
179+
const source = new RemoteSource(client, headers, maxRanges, allowFullFile);
180+
return maybeWrapInBlockedSource(source, blockOptions);
181+
}
182+
178183
/**
179184
*
180185
* @param {string} url

0 commit comments

Comments
 (0)