Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

279
Views
Transmita el archivo (Geo)JSON y obtenga startByte y endByte de cada registro JSON en el archivo

Para archivos JSON/GeoJSON muy grandes, me gustaría crear un almacén primitivo de clave/valor que realice un seguimiento de las posiciones iniciales y las longitudes de cada registro JSON en el archivo. De esta manera, podría buscar registros individuales en una etapa posterior sin leer todo el archivo en la memoria (usando la API fd.read ). Algo similar a una base de datos súper simple, pero de solo lectura y sin sobrecarga adicional.

El problema al que me enfrento es que no sé cómo podría determinar la posición inicial y la longitud de bytes de cada registro JSON/función GeoJSON en el archivo original.

Aquí hay un pseudocódigo que muestra lo que estoy tratando de lograr, tenga en cuenta que la devolución de llamada geojsonStream.parse no recibe los argumentos startByte y length en realidad.

Gracias por su ayuda, también estoy feliz por cualquier comentario que describa por qué esto podría ser una mala idea :)

 import geojsonStream from 'geojson-stream' import { open } from 'fs/promises' import { Buffer } from 'buffer' function getFeaturePositionsInFile(fd) { return new Promise((resolve,reject) => { const featurePositionsInFile = [] const stream = fd .createReadStream() .pipe(geojsonStream.parse((building, index, startByte, length) => { // The startByte and length callback arguments are not real unfortunately :( featurePositionsInFile.push({ index, startPosition, length }) })) stream.on('end', () => resolve(featurePositionsInFile)) stream.on('error', () => reject) }) } function readSingleFeatureFromFile(fd, startPosition, length) { return new Promise((resolve, reject) => { try { const buff = Buffer.alloc(length) const offset = 0 const { buffer } = await fd.read(buff, offset, length, startPosition) const singleFeature = JSON.parse(buffer.toString()) resolve(singleFeature) } catch (e) { reject(e) } }) } const fd = await open('buildings.geojson') const featurePositionsInFile = await getFeaturePositionsInFile(fd) const featureIndexToRead = 0 const { startPosition, length } = featurePositionsInFile[featureIndexToRead] const singleFeature = await readSingleFeatureFromFile(fd, startPosition, length)
over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!