1- import { readFile , writeFile } from 'node:fs/promises' ;
21import { createError } from './errors.js' ;
3- import { decodeTile , encodeTile , inspectTile } from './tile-format.js' ;
4- import { decodeXyzTileId } from './tile-id.js' ;
5- import type { EncodeResult } from './tile-format.js' ;
6- import type { DecodedTile , InspectTileResult , TileEncodeInput } from './types.js' ;
7-
8- export interface InspectTileTextResult {
9- info : InspectTileResult ;
10- text : string ;
11- }
2+ import { decodeTile } from './tile-format.js' ;
3+ import type { DecodedTile } from './types.js' ;
124
135export interface DecodeTileCsvResult {
146 decoded : DecodedTile ;
157 csv : string ;
168}
179
18- export function formatInspectOutput ( info : InspectTileResult ) : string {
19- const lines = [
20- `Format Major: ${ info . header . format_major } ` ,
21- `Tile ID: ${ info . header . tile_id . toString ( ) } ` ,
22- `Mesh Kind: ${ info . header . mesh_kind } ` ,
23- `DType: ${ info . header . dtype } ` ,
24- `Endianness: ${ info . header . endianness } ` ,
25- `Compression: ${ info . header . compression } ` ,
26- `Rows: ${ info . header . dimensions . rows } ` ,
27- `Cols: ${ info . header . dimensions . cols } ` ,
28- `Bands: ${ info . header . dimensions . bands } ` ,
29- `NoData: ${ info . header . no_data === null ? 'null' : String ( info . header . no_data ) } ` ,
30- `Uncompressed Payload Bytes: ${ info . header . payload . uncompressed_bytes } ` ,
31- `Compressed Payload Bytes: ${ info . header . payload . compressed_bytes } ` ,
32- `Payload CRC32: ${ info . header . checksum . payload_crc32 } ` ,
33- `Header CRC32: ${ info . header . checksum . header_crc32 } ` ,
34- `Header Length: ${ info . header_length } ` ,
35- `Payload Offset: ${ info . payload_offset } ` ,
36- `Payload Length: ${ info . payload_length } ` ,
37- ] ;
38-
39- if ( info . header . mesh_kind === 'xyz' ) {
40- const xyz = decodeXyzTileId ( info . header . tile_id ) ;
41- lines . push ( `XYZ Zoom: ${ xyz . zoom } ` ) ;
42- lines . push ( `XYZ X: ${ xyz . x } ` ) ;
43- lines . push ( `XYZ Y: ${ xyz . y } ` ) ;
44- lines . push ( `XYZ Quadkey Integer: ${ xyz . quadkey_integer . toString ( ) } ` ) ;
45- }
46-
47- return lines . join ( '\n' ) ;
48- }
49-
5010export function formatDecodedCsv ( values : ArrayLike < number > , rows : number , cols : number , bands : number ) : string {
5111 const expected = rows * cols * bands ;
5212 if ( values . length !== expected ) {
@@ -72,14 +32,6 @@ export function formatDecodedCsv(values: ArrayLike<number>, rows: number, cols:
7232 return lines . join ( '\n' ) ;
7333}
7434
75- export function inspectTileToText ( bytes : Uint8Array ) : InspectTileTextResult {
76- const info = inspectTile ( bytes ) ;
77- return {
78- info,
79- text : formatInspectOutput ( info ) ,
80- } ;
81- }
82-
8335export async function decodeTileToCsv ( bytes : Uint8Array ) : Promise < DecodeTileCsvResult > {
8436 const decoded = await decodeTile ( bytes ) ;
8537 const { rows, cols, bands } = decoded . header . dimensions ;
@@ -88,19 +40,3 @@ export async function decodeTileToCsv(bytes: Uint8Array): Promise<DecodeTileCsvR
8840 csv : formatDecodedCsv ( decoded . data , rows , cols , bands ) ,
8941 } ;
9042}
91-
92- export async function inspectTileFile ( path : string ) : Promise < InspectTileTextResult > {
93- const bytes = new Uint8Array ( await readFile ( path ) ) ;
94- return inspectTileToText ( bytes ) ;
95- }
96-
97- export async function decodeTileFileToCsv ( path : string ) : Promise < DecodeTileCsvResult > {
98- const bytes = new Uint8Array ( await readFile ( path ) ) ;
99- return decodeTileToCsv ( bytes ) ;
100- }
101-
102- export async function encodeTileToFile ( path : string , input : TileEncodeInput ) : Promise < EncodeResult > {
103- const encoded = await encodeTile ( input ) ;
104- await writeFile ( path , encoded . bytes ) ;
105- return encoded ;
106- }
0 commit comments