Skip to content

Commit

Permalink
fix test import
Browse files Browse the repository at this point in the history
  • Loading branch information
Mr Martian committed Jan 29, 2025
1 parent 910c13e commit 50a4dd3
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 6 deletions.
5 changes: 3 additions & 2 deletions src/converters/toTiles/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import TileWorker from './worker/tileWorker';
import { encodingToCompression } from '../..';
import { xyzToBBOX } from '../../geometry/wm/coords';
import { DrawType, MetadataBuilder } from 's2-tilejson';

Expand Down Expand Up @@ -234,7 +235,7 @@ export interface BuildGuide<V extends MValue = Properties, G extends MValue = Pr
* @param buildGuide - the user defined guide on building the vector tiles
*/
export async function toTiles(buildGuide: BuildGuide): Promise<void> {
const { tileWriter, extension, projection } = buildGuide;
const { tileWriter, extension, projection, encoding } = buildGuide;
const worker = new TileWorker();

// STEP 1: Convert all features to tile slices of said features.
Expand All @@ -257,7 +258,7 @@ export async function toTiles(buildGuide: BuildGuide): Promise<void> {
}
}
// STEP 5: Commit the metadata
await tileWriter.commit(metaBuilder.commit());
await tileWriter.commit(metaBuilder.commit(), encodingToCompression(encoding ?? 'none'));
}

// /**
Expand Down
20 changes: 20 additions & 0 deletions src/util/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { Encoding } from 's2-tilejson';

export * from './gzip';
export * from './lzw';

Expand Down Expand Up @@ -35,6 +37,24 @@ export const Compression = {
*/
export type Compression = (typeof Compression)[keyof typeof Compression];

/**
* Converts a string encoding to a compression algorithm enum
* @param encoding - the encoding as a string
* @returns the compression algorithm as an Enum
*/
export function encodingToCompression(encoding: Encoding): Compression {
switch (encoding) {
case 'gz':
return Compression.Gzip;
case 'br':
return Compression.Brotli;
case 'zstd':
return Compression.Zstd;
default:
return Compression.None;
}
}

/**
* Provide a decompression implementation that acts on `buf` and returns decompressed data.
*
Expand Down
8 changes: 5 additions & 3 deletions tests/readers/pmtiles/pmtiles.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@ import {
deserializeDir,
findTile,
getUint64,
headerToBytes,
serializeDir,
setUint64,
tileIDToZxy,
zxyToTileID,
} from '../../..';
import { headerToBytes, serializeDir, setUint64 } from '../../../src/writers/pmtiles';
} from '../../../src';

import { describe, expect, test } from 'bun:test';

import type { Entry, Header } from '../../..';
import type { Entry, Header } from '../../../src';

test('HEADER_SIZE_BYTES', () => {
expect(HEADER_SIZE_BYTES).toBe(127);
Expand Down
2 changes: 1 addition & 1 deletion tests/writers/pmtiles/writer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { expect, test } from 'bun:test';
import { stat } from 'node:fs/promises';

import type { Metadata } from 's2-tilejson';
import type { S2Header } from '../../../src/readers/pmtiles';
import type { S2Header } from '../../../src';

tmp.setGracefulCleanup();

Expand Down

0 comments on commit 50a4dd3

Please sign in to comment.