@cogeotiff/core 9.3.0 → 9.5.0
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/CHANGELOG.md +27 -0
- package/build/__test__/cog.image.test.js +53 -0
- package/build/__test__/cog.read.test.js +13 -0
- package/build/const/tiff.mime.d.ts +3 -0
- package/build/const/tiff.mime.d.ts.map +1 -1
- package/build/const/tiff.mime.js +23 -0
- package/build/const/tiff.tag.id.d.ts +42 -5
- package/build/const/tiff.tag.id.d.ts.map +1 -1
- package/build/const/tiff.tag.id.js +22 -2
- package/build/read/tiff.tag.factory.d.ts +4 -4
- package/build/read/tiff.tag.factory.d.ts.map +1 -1
- package/build/read/tiff.tag.factory.js +6 -6
- package/build/tiff.d.ts +5 -2
- package/build/tiff.d.ts.map +1 -1
- package/build/tiff.image.d.ts +8 -12
- package/build/tiff.image.d.ts.map +1 -1
- package/build/tiff.image.js +21 -21
- package/build/tiff.js +9 -7
- package/package.json +3 -2
- package/src/__test__/cog.image.test.ts +61 -0
- package/src/__test__/cog.read.test.ts +20 -0
- package/src/const/tiff.mime.ts +23 -0
- package/src/const/tiff.tag.id.ts +45 -4
- package/src/read/tiff.tag.factory.ts +16 -7
- package/src/tiff.image.ts +32 -24
- package/src/tiff.ts +13 -7
package/src/tiff.ts
CHANGED
|
@@ -18,6 +18,10 @@ export interface TiffCreationOptions {
|
|
|
18
18
|
defaultReadSize: number;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
+
export interface TiffFetchOptions {
|
|
22
|
+
signal?: AbortSignal;
|
|
23
|
+
}
|
|
24
|
+
|
|
21
25
|
export class Tiff {
|
|
22
26
|
/** Read 16KB blocks at a time */
|
|
23
27
|
static DefaultReadSize = 16 * 1024;
|
|
@@ -49,9 +53,9 @@ export class Tiff {
|
|
|
49
53
|
/** Create a tiff and initialize it by reading the tiff headers */
|
|
50
54
|
static create(
|
|
51
55
|
source: Source,
|
|
52
|
-
options: TiffCreationOptions = { defaultReadSize: Tiff.DefaultReadSize },
|
|
56
|
+
options: TiffCreationOptions & TiffFetchOptions = { defaultReadSize: Tiff.DefaultReadSize },
|
|
53
57
|
): Promise<Tiff> {
|
|
54
|
-
return new Tiff(source, options).init();
|
|
58
|
+
return new Tiff(source, options).init(options);
|
|
55
59
|
}
|
|
56
60
|
|
|
57
61
|
/**
|
|
@@ -60,9 +64,10 @@ export class Tiff {
|
|
|
60
64
|
* This is only required if the Tiff was created with the constructor, if you
|
|
61
65
|
* used {@link create} this will have already been called.
|
|
62
66
|
*/
|
|
63
|
-
init(): Promise<Tiff> {
|
|
67
|
+
init(options?: TiffFetchOptions): Promise<Tiff> {
|
|
68
|
+
if (this.isInitialized) return Promise.resolve(this);
|
|
64
69
|
if (this._initPromise) return this._initPromise;
|
|
65
|
-
this._initPromise = this.readHeader();
|
|
70
|
+
this._initPromise = this.readHeader(options);
|
|
66
71
|
return this._initPromise;
|
|
67
72
|
}
|
|
68
73
|
|
|
@@ -92,11 +97,11 @@ export class Tiff {
|
|
|
92
97
|
}
|
|
93
98
|
|
|
94
99
|
/** Read the Starting header and all Image headers from the source */
|
|
95
|
-
private async readHeader(): Promise<Tiff> {
|
|
100
|
+
private async readHeader(options?: TiffFetchOptions): Promise<Tiff> {
|
|
96
101
|
if (this.isInitialized) return this;
|
|
97
102
|
// limit the read to the size of the file if it is known, for small tiffs
|
|
98
103
|
const bytes = new DataView(
|
|
99
|
-
await this.source.fetch(0, getMaxLength(this.source, 0, this.defaultReadSize)),
|
|
104
|
+
await this.source.fetch(0, getMaxLength(this.source, 0, this.defaultReadSize), options),
|
|
100
105
|
) as DataViewOffset;
|
|
101
106
|
if (bytes.byteLength === 0) throw new Error('Unable to read empty tiff');
|
|
102
107
|
|
|
@@ -144,6 +149,7 @@ export class Tiff {
|
|
|
144
149
|
const bytes = await this.source.fetch(
|
|
145
150
|
nextOffsetIfd,
|
|
146
151
|
getMaxLength(this.source, nextOffsetIfd, this.defaultReadSize),
|
|
152
|
+
options,
|
|
147
153
|
);
|
|
148
154
|
lastView = new DataView(bytes) as DataViewOffset;
|
|
149
155
|
lastView.sourceOffset = nextOffsetIfd;
|
|
@@ -151,7 +157,7 @@ export class Tiff {
|
|
|
151
157
|
nextOffsetIfd = this.readIfd(nextOffsetIfd, lastView);
|
|
152
158
|
}
|
|
153
159
|
|
|
154
|
-
await Promise.all(this.images.map((i) => i.init()));
|
|
160
|
+
await Promise.all(this.images.map((i) => i.init(true, options)));
|
|
155
161
|
this.isInitialized = true;
|
|
156
162
|
return this;
|
|
157
163
|
}
|