From 759e51fe051bf7f1d471f1da1af6a1431a227b81 Mon Sep 17 00:00:00 2001 From: Andrew Calcutt Date: Fri, 13 Oct 2023 11:01:16 -0400 Subject: [PATCH] fix: remove PMtilesClose I'm not sure this is really needed Signed-off-by: Andrew Calcutt --- src/main.js | 12 ++---------- src/pmtiles_adapter.js | 13 ++----------- src/serve_data.js | 5 ++--- src/serve_rendered.js | 5 ++--- 4 files changed, 8 insertions(+), 27 deletions(-) diff --git a/src/main.js b/src/main.js index f9e2859..27a40b6 100644 --- a/src/main.js +++ b/src/main.js @@ -9,11 +9,7 @@ import request from 'request'; import { server } from './server.js'; import MBTiles from '@mapbox/mbtiles'; import { isValidHttpUrl } from './utils.js'; -import { - PMtilesOpen, - PMtilesClose, - GetPMtilesInfo, -} from './pmtiles_adapter.js'; +import { PMtilesOpen, GetPMtilesInfo } from './pmtiles_adapter.js'; const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); @@ -128,11 +124,7 @@ const StartWithInputFile = async (inputFile) => { const extension = inputFile.split('.').pop().toLowerCase(); if (extension === 'pmtiles') { let FileOpenInfo = PMtilesOpen(inputFile); - const metadata = await GetPMtilesInfo(FileOpenInfo.pmtiles); - if (FileOpenInfo.fd !== undefined) { - PMtilesClose(FileOpenInfo.fd); - } - FileOpenInfo = null; + const metadata = await GetPMtilesInfo(FileOpenInfo); if ( metadata.format === 'pbf' && diff --git a/src/pmtiles_adapter.js b/src/pmtiles_adapter.js index fa5c885..a827584 100644 --- a/src/pmtiles_adapter.js +++ b/src/pmtiles_adapter.js @@ -43,25 +43,16 @@ async function ReadFileBytes(fd, buffer, offset) { */ export function PMtilesOpen(FilePath) { let pmtiles = undefined; - let fd = undefined; if (isValidHttpUrl(FilePath)) { const source = new PMTiles.FetchSource(FilePath); pmtiles = new PMTiles.PMTiles(source); } else { - fd = fs.openSync(FilePath, 'r'); + const fd = fs.openSync(FilePath, 'r'); const source = new PMTilesFileSource(fd); pmtiles = new PMTiles.PMTiles(source); } - return { pmtiles: pmtiles, fd: fd }; -} - -/** - * - * @param fd - */ -export function PMtilesClose(fd) { - fs.closeSync(fd); + return pmtiles; } /** diff --git a/src/serve_data.js b/src/serve_data.js index f4e5b97..80e3d5b 100644 --- a/src/serve_data.js +++ b/src/serve_data.js @@ -225,10 +225,9 @@ export const serve_data = { let source; let source_type; if (inputType === 'pmtiles') { - let FileOpenInfo = PMtilesOpen(inputFile); - const metadata = await GetPMtilesInfo(FileOpenInfo.pmtiles); - source = FileOpenInfo.pmtiles; + source = PMtilesOpen(inputFile); source_type = 'pmtiles'; + const metadata = await GetPMtilesInfo(source); tileJSON['name'] = id; tileJSON['format'] = 'pbf'; diff --git a/src/serve_rendered.js b/src/serve_rendered.js index 192bd2c..872cf3a 100644 --- a/src/serve_rendered.js +++ b/src/serve_rendered.js @@ -1507,10 +1507,9 @@ export const serve_rendered = { } if (source_type === 'pmtiles') { - let FileOpenInfo = PMtilesOpen(inputFile); - const metadata = await GetPMtilesInfo(FileOpenInfo.pmtiles); - map.sources[name] = FileOpenInfo.pmtiles; + map.sources[name] = PMtilesOpen(inputFile); map.source_types[name] = 'pmtiles'; + const metadata = await GetPMtilesInfo(map.sources[name]); if (!repoobj.dataProjWGStoInternalWGS && metadata.proj4) { // how to do this for multiple sources with different proj4 defs?