Skip to content

Commit

Permalink
Merge pull request #370 from sguimmara/expose-remote-source
Browse files Browse the repository at this point in the history
Make it possible to build a RemoteSource with a user-provided client
  • Loading branch information
constantinius authored Jul 31, 2023
2 parents f15d770 + 2277172 commit d6b48ad
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/geotiff.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import DataView64 from './dataview64.js';
import DataSlice from './dataslice.js';
import Pool from './pool.js';

import { makeRemoteSource } from './source/remote.js';
import { makeRemoteSource, makeCustomSource } from './source/remote.js';
import { makeBufferSource } from './source/arraybuffer.js';
import { makeFileReaderSource } from './source/filereader.js';
import { makeFileSource } from './source/file.js';
import { BaseClient, BaseResponse } from './source/client/base.js';

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

/**
* Creates a new GeoTIFF from a custom {@link BaseClient}.
* @param {BaseClient} client The client.
* @param {object} [options] Additional options to pass to the source.
* See {@link makeRemoteSource} for details.
* @param {AbortSignal} [signal] An AbortSignal that may be signalled if the request is
* to be aborted
* @returns {Promise<GeoTIFF>} The resulting GeoTIFF file.
*/
export async function fromCustomClient(client, options = {}, signal) {
return GeoTIFF.fromSource(makeCustomSource(client, options), signal);
}

/**
* Construct a new GeoTIFF from an
* [ArrayBuffer]{@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer}.
Expand Down Expand Up @@ -757,3 +771,4 @@ export function writeArrayBuffer(values, metadata) {

export { Pool };
export { GeoTIFFImage };
export { BaseClient, BaseResponse };
5 changes: 5 additions & 0 deletions src/source/remote.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,11 @@ export function makeHttpSource(url, { headers = {}, maxRanges = 0, allowFullFile
return maybeWrapInBlockedSource(source, blockOptions);
}

export function makeCustomSource(client, { headers = {}, maxRanges = 0, allowFullFile = false, ...blockOptions } = {}) {
const source = new RemoteSource(client, headers, maxRanges, allowFullFile);
return maybeWrapInBlockedSource(source, blockOptions);
}

/**
*
* @param {string} url
Expand Down

0 comments on commit d6b48ad

Please sign in to comment.