-
Notifications
You must be signed in to change notification settings - Fork 0
/
is-cog.js
36 lines (29 loc) · 1.03 KB
/
is-cog.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
const idTIF = require("id-tif");
const isGeoTIFF = require("is-geotiff");
const hasBytes = require("has-bytes");
module.exports = function isCOG({ data, debug, is_geotiff, is_tiff }) {
if (debug) console.log("[is-cog] starting with data", data);
if (is_tiff === undefined) is_tiff = idTIF(data, debug);
// return early if not a TIFF file
if (!is_tiff) {
if (debug) console.log("file is not a tiff, so returning early");
return { is_cog: false, is_geotiff: false, is_tiff };
}
if (is_geotiff === undefined) is_geotiff = isGeoTIFF({ data, debug }).result;
// return early if not a GeoTIFF file
if (!is_geotiff) {
if (debug) console.log("file is not a geotiff, so returning early");
return { is_cog: false, is_geotiff, is_tiff };
}
const { result } = hasBytes({
data,
debug,
sequences: {
TileWidth: [66, 1], // 0x0142
TileLength: [67, 1], // 0x0143
TileOffsets: [68, 1], // 0x0144
TileByteCounts: [69, 1] // 0x0145
}
});
return { is_cog: result, is_geotiff, is_tiff };
};