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 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' &&

View file

@ -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;
}
/**

View file

@ -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';

View file

@ -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?