This commit is contained in:
30
node_modules/geotiff/dist-module/source/client/base.d.ts
generated
vendored
Normal file
30
node_modules/geotiff/dist-module/source/client/base.d.ts
generated
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
export class BaseResponse {
|
||||
/**
|
||||
* Returns whether the response has an ok'ish status code
|
||||
*/
|
||||
get ok(): boolean;
|
||||
/**
|
||||
* Returns the status code of the response
|
||||
*/
|
||||
get status(): void;
|
||||
/**
|
||||
* Returns the value of the specified header
|
||||
* @param {string} headerName the header name
|
||||
* @returns {string} the header value
|
||||
*/
|
||||
getHeader(headerName: string): string;
|
||||
/**
|
||||
* @returns {ArrayBuffer} the response data of the request
|
||||
*/
|
||||
getData(): ArrayBuffer;
|
||||
}
|
||||
export class BaseClient {
|
||||
constructor(url: any);
|
||||
url: any;
|
||||
/**
|
||||
* Send a request with the options
|
||||
* @param {object} [options]
|
||||
*/
|
||||
request({ headers, credentials, signal }?: object): Promise<void>;
|
||||
}
|
||||
//# sourceMappingURL=base.d.ts.map
|
||||
1
node_modules/geotiff/dist-module/source/client/base.d.ts.map
generated
vendored
Normal file
1
node_modules/geotiff/dist-module/source/client/base.d.ts.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../../src/source/client/base.js"],"names":[],"mappings":"AAAA;IACE;;OAEG;IACH,kBAEC;IAED;;OAEG;IACH,mBAEC;IAED;;;;OAIG;IACH,sBAHW,MAAM,GACJ,MAAM,CAIlB;IAED;;OAEG;IACH,WAFa,WAAW,CAIvB;CACF;AAED;IACE,sBAEC;IADC,SAAc;IAGhB;;;OAGG;IACH,2CAFW,MAAM,iBAIhB;CACF"}
|
||||
45
node_modules/geotiff/dist-module/source/client/base.js
generated
vendored
Normal file
45
node_modules/geotiff/dist-module/source/client/base.js
generated
vendored
Normal file
@@ -0,0 +1,45 @@
|
||||
export class BaseResponse {
|
||||
/**
|
||||
* Returns whether the response has an ok'ish status code
|
||||
*/
|
||||
get ok() {
|
||||
return this.status >= 200 && this.status <= 299;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the status code of the response
|
||||
*/
|
||||
get status() {
|
||||
throw new Error('not implemented');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value of the specified header
|
||||
* @param {string} headerName the header name
|
||||
* @returns {string} the header value
|
||||
*/
|
||||
getHeader(headerName) { // eslint-disable-line no-unused-vars
|
||||
throw new Error('not implemented');
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {ArrayBuffer} the response data of the request
|
||||
*/
|
||||
async getData() {
|
||||
throw new Error('not implemented');
|
||||
}
|
||||
}
|
||||
|
||||
export class BaseClient {
|
||||
constructor(url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a request with the options
|
||||
* @param {object} [options]
|
||||
*/
|
||||
async request({ headers, credentials, signal } = {}) { // eslint-disable-line no-unused-vars
|
||||
throw new Error('request is not implemented');
|
||||
}
|
||||
}
|
||||
6
node_modules/geotiff/dist-module/source/client/fetch.d.ts
generated
vendored
Normal file
6
node_modules/geotiff/dist-module/source/client/fetch.d.ts
generated
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
export class FetchClient extends BaseClient {
|
||||
constructor(url: any, credentials: any);
|
||||
credentials: any;
|
||||
}
|
||||
import { BaseClient } from "./base.js";
|
||||
//# sourceMappingURL=fetch.d.ts.map
|
||||
1
node_modules/geotiff/dist-module/source/client/fetch.d.ts.map
generated
vendored
Normal file
1
node_modules/geotiff/dist-module/source/client/fetch.d.ts.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"fetch.d.ts","sourceRoot":"","sources":["../../../src/source/client/fetch.js"],"names":[],"mappings":"AA4BA;IACE,wCAGC;IADC,iBAA8B;CASjC"}
|
||||
41
node_modules/geotiff/dist-module/source/client/fetch.js
generated
vendored
Normal file
41
node_modules/geotiff/dist-module/source/client/fetch.js
generated
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
import { BaseClient, BaseResponse } from './base.js';
|
||||
|
||||
class FetchResponse extends BaseResponse {
|
||||
/**
|
||||
* BaseResponse facade for fetch API Response
|
||||
* @param {Response} response
|
||||
*/
|
||||
constructor(response) {
|
||||
super();
|
||||
this.response = response;
|
||||
}
|
||||
|
||||
get status() {
|
||||
return this.response.status;
|
||||
}
|
||||
|
||||
getHeader(name) {
|
||||
return this.response.headers.get(name);
|
||||
}
|
||||
|
||||
async getData() {
|
||||
const data = this.response.arrayBuffer
|
||||
? await this.response.arrayBuffer()
|
||||
: (await this.response.buffer()).buffer;
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
export class FetchClient extends BaseClient {
|
||||
constructor(url, credentials) {
|
||||
super(url);
|
||||
this.credentials = credentials;
|
||||
}
|
||||
|
||||
async request({ headers, credentials, signal } = {}) {
|
||||
const response = await fetch(this.url, {
|
||||
headers, credentials, signal,
|
||||
});
|
||||
return new FetchResponse(response);
|
||||
}
|
||||
}
|
||||
7
node_modules/geotiff/dist-module/source/client/http.d.ts
generated
vendored
Normal file
7
node_modules/geotiff/dist-module/source/client/http.d.ts
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
export class HttpClient extends BaseClient {
|
||||
parsedUrl: any;
|
||||
httpApi: any;
|
||||
constructRequest(headers: any, signal: any): Promise<any>;
|
||||
}
|
||||
import { BaseClient } from "./base.js";
|
||||
//# sourceMappingURL=http.d.ts.map
|
||||
1
node_modules/geotiff/dist-module/source/client/http.d.ts.map
generated
vendored
Normal file
1
node_modules/geotiff/dist-module/source/client/http.d.ts.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../../src/source/client/http.js"],"names":[],"mappings":"AAgCA;IAGI,eAAuC;IACvC,aAAmE;IAGrE,0DAmCC;CAMF"}
|
||||
81
node_modules/geotiff/dist-module/source/client/http.js
generated
vendored
Normal file
81
node_modules/geotiff/dist-module/source/client/http.js
generated
vendored
Normal file
@@ -0,0 +1,81 @@
|
||||
import http from 'http';
|
||||
import https from 'https';
|
||||
import urlMod from 'url';
|
||||
|
||||
import { BaseClient, BaseResponse } from './base.js';
|
||||
import { AbortError } from '../../utils.js';
|
||||
|
||||
class HttpResponse extends BaseResponse {
|
||||
/**
|
||||
* BaseResponse facade for node HTTP/HTTPS API Response
|
||||
* @param {http.ServerResponse} response
|
||||
*/
|
||||
constructor(response, dataPromise) {
|
||||
super();
|
||||
this.response = response;
|
||||
this.dataPromise = dataPromise;
|
||||
}
|
||||
|
||||
get status() {
|
||||
return this.response.statusCode;
|
||||
}
|
||||
|
||||
getHeader(name) {
|
||||
return this.response.headers[name];
|
||||
}
|
||||
|
||||
async getData() {
|
||||
const data = await this.dataPromise;
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
export class HttpClient extends BaseClient {
|
||||
constructor(url) {
|
||||
super(url);
|
||||
this.parsedUrl = urlMod.parse(this.url);
|
||||
this.httpApi = (this.parsedUrl.protocol === 'http:' ? http : https);
|
||||
}
|
||||
|
||||
constructRequest(headers, signal) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const request = this.httpApi.get(
|
||||
{
|
||||
...this.parsedUrl,
|
||||
headers,
|
||||
},
|
||||
(response) => {
|
||||
const dataPromise = new Promise((resolveData) => {
|
||||
const chunks = [];
|
||||
|
||||
// collect chunks
|
||||
response.on('data', (chunk) => {
|
||||
chunks.push(chunk);
|
||||
});
|
||||
|
||||
// concatenate all chunks and resolve the promise with the resulting buffer
|
||||
response.on('end', () => {
|
||||
const data = Buffer.concat(chunks).buffer;
|
||||
resolveData(data);
|
||||
});
|
||||
response.on('error', reject);
|
||||
});
|
||||
resolve(new HttpResponse(response, dataPromise));
|
||||
},
|
||||
);
|
||||
request.on('error', reject);
|
||||
|
||||
if (signal) {
|
||||
if (signal.aborted) {
|
||||
request.destroy(new AbortError('Request aborted'));
|
||||
}
|
||||
signal.addEventListener('abort', () => request.destroy(new AbortError('Request aborted')));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
async request({ headers, signal } = {}) {
|
||||
const response = await this.constructRequest(headers, signal);
|
||||
return response;
|
||||
}
|
||||
}
|
||||
5
node_modules/geotiff/dist-module/source/client/xhr.d.ts
generated
vendored
Normal file
5
node_modules/geotiff/dist-module/source/client/xhr.d.ts
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
export class XHRClient extends BaseClient {
|
||||
constructRequest(headers: any, signal: any): Promise<any>;
|
||||
}
|
||||
import { BaseClient } from "./base.js";
|
||||
//# sourceMappingURL=xhr.d.ts.map
|
||||
1
node_modules/geotiff/dist-module/source/client/xhr.d.ts.map
generated
vendored
Normal file
1
node_modules/geotiff/dist-module/source/client/xhr.d.ts.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"xhr.d.ts","sourceRoot":"","sources":["../../../src/source/client/xhr.js"],"names":[],"mappings":"AA4BA;IACE,0DAyBC;CAMF"}
|
||||
61
node_modules/geotiff/dist-module/source/client/xhr.js
generated
vendored
Normal file
61
node_modules/geotiff/dist-module/source/client/xhr.js
generated
vendored
Normal file
@@ -0,0 +1,61 @@
|
||||
import { BaseClient, BaseResponse } from './base.js';
|
||||
import { AbortError } from '../../utils.js';
|
||||
|
||||
class XHRResponse extends BaseResponse {
|
||||
/**
|
||||
* BaseResponse facade for XMLHttpRequest
|
||||
* @param {XMLHttpRequest} xhr
|
||||
* @param {ArrayBuffer} data
|
||||
*/
|
||||
constructor(xhr, data) {
|
||||
super();
|
||||
this.xhr = xhr;
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
get status() {
|
||||
return this.xhr.status;
|
||||
}
|
||||
|
||||
getHeader(name) {
|
||||
return this.xhr.getResponseHeader(name);
|
||||
}
|
||||
|
||||
async getData() {
|
||||
return this.data;
|
||||
}
|
||||
}
|
||||
|
||||
export class XHRClient extends BaseClient {
|
||||
constructRequest(headers, signal) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const xhr = new XMLHttpRequest();
|
||||
xhr.open('GET', this.url);
|
||||
xhr.responseType = 'arraybuffer';
|
||||
for (const [key, value] of Object.entries(headers)) {
|
||||
xhr.setRequestHeader(key, value);
|
||||
}
|
||||
|
||||
// hook signals
|
||||
xhr.onload = () => {
|
||||
const data = xhr.response;
|
||||
resolve(new XHRResponse(xhr, data));
|
||||
};
|
||||
xhr.onerror = reject;
|
||||
xhr.onabort = () => reject(new AbortError('Request aborted'));
|
||||
xhr.send();
|
||||
|
||||
if (signal) {
|
||||
if (signal.aborted) {
|
||||
xhr.abort();
|
||||
}
|
||||
signal.addEventListener('abort', () => xhr.abort());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
async request({ headers, signal } = {}) {
|
||||
const response = await this.constructRequest(headers, signal);
|
||||
return response;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user