Coder Social home page Coder Social logo

Comments (2)

pgleghorn avatar pgleghorn commented on September 26, 2024 1

Hi @vweevers , sure the createReadStream is pretty much a copy from the readme:

function fetchAll() {
  const db = level('leveldb')
  db.createReadStream()
    .on('data', function (data) {
      console.log(data.key, '=', data.value)
    })
    .on('error', function (err) {
      console.log('Oh my!', err)
    })
    .on('close', function () {
      console.log('Stream closed')
    })
    .on('end', function () {
      console.log('Stream ended')
    })
}

But I just figured out the problem, there are some non-printable characters in the keys. I used createReadStream to fetch everything and write the keys into files, so that I could hex dump them:

$ xxd key3
00000000: 5f66 696c 653a 2f2f 0001 6462 496e 6974  _file://..dbInit
00000010: 436f 6e74 6578 74                        Context

No idea what's up with these funky hidden chars, but now I succeed to fetch them via db.get using a suitable matching key:

  var funkyKey = "_file://\000\001dbInitContext"
  console.log(`fetching dbInitContext with a funky key: ${await db.get(funkyKey)}`);

n.b I thought I might need to use {keyEncoding: 'binary'} on the db.get options, but turns out it works regardless.

Thx
Phil

from level.

vweevers avatar vweevers commented on September 26, 2024

For example using createReadStream

Can you share that code as well? So we can see the difference.

from level.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.