npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

stream-dbf

v0.3.0

Published

A dBase DBF file parser that outputs a node stream.

Downloads

344

Readme

stream-dbf

A dBase DBF file parser that outputs a node stream.

stream-dbf uses the logic from abstractvector's node-dbf in a Transform stream. It's written in plain JavaScript.

npm install stream-dbf

Usage

Create a new instance of the parser by specifying the file path of the dBase file, and optionally any of the options flags (described below).

var DBF = require('stream-dbf');
var parser = new DBF(fileName, [options]);

options

  • parseTypes - default: true - If false, integers and floats will be returned as strings.
  • recAsArray - default: false - If true, stream will emit arrays instead objects (this slightly improve throughput).
  • encoding - default: "utf-8" - It is passed to the iconv-lite to decode the field names and values in order to support encodings like GBK etc.
  • lowercase - default: false - If true, the field names will be converted to lowercase.
  • withMeta - default: true - If true, each record will contain two meta fields named "@sequenceNumber" and "@deleted".

parser.stream

Attach standard stream listeners to this object to access the records.

var stream = parser.stream;
stream.on('readable', function() {
  var record = stream.read();
  // do something with the record
});
stream.on('end', function() {
  console.log('finished');
});

You can also use the stream in flowing mode by attaching a data event listener.

var stream = parser.stream;
stream.on('data', function(record) {
  // do something with the record
});
stream.on('end', function() {
  console.log('finished');
});

Lastly, you can also pipe the stream like you would any other readable stream.

var stream = parser.stream;
var writableStream = somehowGetWritableStream();
stream.pipe(writableStream);

parser.header

Returns the header object, which contains information like the modified date, number of records, and a list of the fields and their types and lengths.

parser.header.fields

Array object which contains information about fields. Every item is an object with next fields: name, type, displacement, length, decimalPlaces, indexFlag.

parser.header.fields.raw

If need, field value can be returned as raw buffer for custom parsing (e.g. convert encodings). To enable this behavior you need set raw property to true:

var DBF = require('stream-dbf');
var parser = new DBF(fileName, [options]);
parser.header.fields[1].raw = true;

Array mode

If recAsArray option is enabled emitted arrays will have parser.header.fields.length+2 items. Zero number item will be sequenceNumber and first item will be a deleted flag.

For searching field number by you can use getFieldNo(name[, case_sensitivity]) function:

var DBF = require('stream-dbf');
var parser = new DBF(fileName, {'recAsArray': true});
var idxName = parser.getFieldNo("Name");
parser.stream.on('data', function(record) {
  console.log("Name: " + record[idxName]);
});