fix: remove PMtilesClose

I'm not sure this is really needed

Signed-off-by: Andrew Calcutt <acalcutt@techidiots.net>
This commit is contained in:
Andrew Calcutt 2023-10-13 11:01:16 -04:00
parent 371bde7070
commit 759e51fe05
4 changed files with 8 additions and 27 deletions

View file

@ -9,11 +9,7 @@ import request from 'request';
import { server } from './server.js'; import { server } from './server.js';
import MBTiles from '@mapbox/mbtiles'; import MBTiles from '@mapbox/mbtiles';
import { isValidHttpUrl } from './utils.js'; import { isValidHttpUrl } from './utils.js';
import { import { PMtilesOpen, GetPMtilesInfo } from './pmtiles_adapter.js';
PMtilesOpen,
PMtilesClose,
GetPMtilesInfo,
} from './pmtiles_adapter.js';
const __filename = fileURLToPath(import.meta.url); const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename); const __dirname = path.dirname(__filename);
@ -128,11 +124,7 @@ const StartWithInputFile = async (inputFile) => {
const extension = inputFile.split('.').pop().toLowerCase(); const extension = inputFile.split('.').pop().toLowerCase();
if (extension === 'pmtiles') { if (extension === 'pmtiles') {
let FileOpenInfo = PMtilesOpen(inputFile); let FileOpenInfo = PMtilesOpen(inputFile);
const metadata = await GetPMtilesInfo(FileOpenInfo.pmtiles); const metadata = await GetPMtilesInfo(FileOpenInfo);
if (FileOpenInfo.fd !== undefined) {
PMtilesClose(FileOpenInfo.fd);
}
FileOpenInfo = null;
if ( if (
metadata.format === 'pbf' && metadata.format === 'pbf' &&

View file

@ -43,25 +43,16 @@ async function ReadFileBytes(fd, buffer, offset) {
*/ */
export function PMtilesOpen(FilePath) { export function PMtilesOpen(FilePath) {
let pmtiles = undefined; let pmtiles = undefined;
let fd = undefined;
if (isValidHttpUrl(FilePath)) { if (isValidHttpUrl(FilePath)) {
const source = new PMTiles.FetchSource(FilePath); const source = new PMTiles.FetchSource(FilePath);
pmtiles = new PMTiles.PMTiles(source); pmtiles = new PMTiles.PMTiles(source);
} else { } else {
fd = fs.openSync(FilePath, 'r'); const fd = fs.openSync(FilePath, 'r');
const source = new PMTilesFileSource(fd); const source = new PMTilesFileSource(fd);
pmtiles = new PMTiles.PMTiles(source); pmtiles = new PMTiles.PMTiles(source);
} }
return { pmtiles: pmtiles, fd: fd }; return pmtiles;
}
/**
*
* @param fd
*/
export function PMtilesClose(fd) {
fs.closeSync(fd);
} }
/** /**

View file

@ -225,10 +225,9 @@ export const serve_data = {
let source; let source;
let source_type; let source_type;
if (inputType === 'pmtiles') { if (inputType === 'pmtiles') {
let FileOpenInfo = PMtilesOpen(inputFile); source = PMtilesOpen(inputFile);
const metadata = await GetPMtilesInfo(FileOpenInfo.pmtiles);
source = FileOpenInfo.pmtiles;
source_type = 'pmtiles'; source_type = 'pmtiles';
const metadata = await GetPMtilesInfo(source);
tileJSON['name'] = id; tileJSON['name'] = id;
tileJSON['format'] = 'pbf'; tileJSON['format'] = 'pbf';

View file

@ -1507,10 +1507,9 @@ export const serve_rendered = {
} }
if (source_type === 'pmtiles') { if (source_type === 'pmtiles') {
let FileOpenInfo = PMtilesOpen(inputFile); map.sources[name] = PMtilesOpen(inputFile);
const metadata = await GetPMtilesInfo(FileOpenInfo.pmtiles);
map.sources[name] = FileOpenInfo.pmtiles;
map.source_types[name] = 'pmtiles'; map.source_types[name] = 'pmtiles';
const metadata = await GetPMtilesInfo(map.sources[name]);
if (!repoobj.dataProjWGStoInternalWGS && metadata.proj4) { if (!repoobj.dataProjWGStoInternalWGS && metadata.proj4) {
// how to do this for multiple sources with different proj4 defs? // how to do this for multiple sources with different proj4 defs?