chiitiler 1.12.6 → 1.12.7
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/README.md +1 -0
- package/dist/source/pmtiles.js +23 -15
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -264,6 +264,7 @@ const s3Cache = ChiitilerCache.s3Cache({
|
|
|
264
264
|
region: 'ap-northeast-1',
|
|
265
265
|
endpoint: null,
|
|
266
266
|
});
|
|
267
|
+
// credentials are loaded from environment variables: AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY
|
|
267
268
|
|
|
268
269
|
const tileBuf = await getRenderedTileBuffer({
|
|
269
270
|
stylejson: 'https://example.com/style.json', // or StyleSpecification object
|
package/dist/source/pmtiles.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as fs from 'fs';
|
|
2
2
|
import { PMTiles } from 'pmtiles';
|
|
3
|
-
import { GetObjectCommand } from '@aws-sdk/client-s3';
|
|
3
|
+
import { GetObjectCommand, } from '@aws-sdk/client-s3';
|
|
4
4
|
import { LRUCache } from 'lru-cache';
|
|
5
5
|
import { getS3Client } from '../s3.js';
|
|
6
6
|
import { noneCache } from '../cache/index.js';
|
|
@@ -39,24 +39,32 @@ class S3Source {
|
|
|
39
39
|
getKey() {
|
|
40
40
|
return `s3://${this.bucket}/${this.key}`;
|
|
41
41
|
}
|
|
42
|
-
async getBytes(offset, length) {
|
|
43
|
-
|
|
44
|
-
Bucket: this.bucket,
|
|
45
|
-
Key: this.key,
|
|
46
|
-
Range: `bytes=${offset}-${offset + length - 1}`,
|
|
47
|
-
});
|
|
42
|
+
async getBytes(offset, length, signal, etag) {
|
|
43
|
+
let resp;
|
|
48
44
|
try {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
45
|
+
resp = await this.s3Client.send(new GetObjectCommand({
|
|
46
|
+
Bucket: this.bucket,
|
|
47
|
+
Key: this.key,
|
|
48
|
+
Range: 'bytes=' + offset + '-' + (offset + length - 1),
|
|
49
|
+
IfMatch: etag,
|
|
50
|
+
}));
|
|
54
51
|
}
|
|
55
52
|
catch (e) {
|
|
56
|
-
if (e
|
|
57
|
-
|
|
58
|
-
|
|
53
|
+
if (e instanceof Error &&
|
|
54
|
+
e.name === 'PreconditionFailed') {
|
|
55
|
+
throw new Error('etag mismatch');
|
|
56
|
+
}
|
|
57
|
+
throw e;
|
|
59
58
|
}
|
|
59
|
+
const arr = await resp.Body?.transformToByteArray();
|
|
60
|
+
if (!arr)
|
|
61
|
+
throw Error('Failed to read S3 response body');
|
|
62
|
+
return {
|
|
63
|
+
data: arr.buffer,
|
|
64
|
+
etag: resp.ETag,
|
|
65
|
+
expires: resp.Expires?.toISOString(),
|
|
66
|
+
cacheControl: resp.CacheControl,
|
|
67
|
+
};
|
|
60
68
|
}
|
|
61
69
|
}
|
|
62
70
|
/**
|