Giter VIP home page Giter VIP logo

dbf's Introduction

dbf

Build Status


Looking for new maintainers!

This project is currently unmaintained. We'd love to turn it over to a new maintainer. If you're interested, please file an issue!


Write dBase files in pure JavaScript, in node.js or browsers. Requires ArrayBuffer and DataView support.

usage

npm install dbf

Or just in a browser:

https://unpkg.com/dbf@latest/dbf.js

Replace latest with the latest version if you want to be sure.

example

in node:

var dbf = require('../'),
    fs = require('fs');

var buf = dbf.structure([
    {foo:'bar',noo:10},
    {foo:'louie'}
]);

fs.writeFileSync('foo.dbf', toBuffer(buf.buffer));

function toBuffer(ab) {
    var buffer = new Buffer(ab.byteLength);
    var view = new Uint8Array(ab);
    for (var i = 0; i < buffer.length; ++i) {
        buffer[i] = view[i];
    }
    return buffer;
}

API

dbf.structure(array)

Given an array of objects with string or number attributes, return a DataView object referencing an ArrayBuffer that contains a full DBF file structure.

Specifications

dbf's People

Contributors

calvinmetcalf avatar davidtheclark avatar faandi avatar kriscarle avatar mhkeller avatar npmcdn-to-unpkg-bot avatar sheindel avatar thibaudlopez avatar tmcw avatar yortus avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

dbf's Issues

Fallback if column has only null

If a column has only null values we cant calc the size for the buffer.
So i think a fallback to String would be fine.
Example:

function obj(_) {
    var fields = {}, o = [];
    for (var p in _) fields[p] = typeof _[p];
    for (var n in fields) {
        var t = types[fields[n]];
        o.push({
            name: n,
            type: t || 'C',
            size: fieldSize[t] || fieldSize['C']
        });
    }
    return o;
}

ๆˆ‘้ 

Hi! ๐Ÿ‘‹

Firstly, thanks for your work on this project! ๐Ÿ™‚

Today I used patch-package to patch [email protected] for the project I'm working on.

Here is the diff that solved my problem:

diff --git a/node_modules/dbf/src/structure.js b/node_modules/dbf/src/structure.js
index 4b02783..f2b4c0b 100644
--- a/node_modules/dbf/src/structure.js
+++ b/node_modules/dbf/src/structure.js
@@ -55,7 +55,7 @@ module.exports = function structure(data, meta) {
         if (f.type == 'N') view.setInt8(32 + i * 32 + 17, 3);
     });
 
-    offset = fieldDescLength + 32;
+    var offset = fieldDescLength + 32;
 
     data.forEach(function(row, num) {
         // delete flag: this is not deleted

This issue body was partially generated by patch-package.

New maintainer

Hi, I'm thinking on migrate my vfp based invoice system into electron and I saw that you need help.

What can I help with?

Chinese character messe...

when i use this lib to save data which contains chinese character, it works. But when i open the dbf file, the character is mess. How can i solve this problem. Thank u.

Last Modified Date in Header off by 1

I have used this node and works well except for any file exported in the month of January. When trying to import the dbf into Word perfect, the file is reported to be of an unsupported format. Upon review of the DBF file header, the Last Modified Date for the month of January shows a value of "00" and February is "01", etc...
Standard applications such as Excel and Quattro certainly don't care about the file header but Word Perfect seems to and throws a file format error. I have attached 2 screenshots of the said error. 1 was created Jan 2018 and the other in Feb 2017 for reference.

dbf file error feb 2017
dbf file error jan 2018

'offset' is not defined

i'm get the error 'offset' is not defined because i use strict mode.
so the fix for this kind of issue is to change

in dbf/src/structure.js

(line number 58)
from:

offset = fieldDescLength + 32;

to:

var offset = fieldDescLength + 32;

Date support

Would it be possible to have javascript date support? From the source of structure.js it looks like it is at least partially supported, but is there anything blocking having the fields.js script resolve date types in addition to numbers, strings, and booleans?

Willing to submit a PR, but didn't want to waste my time if it wasn't possible/desired.

solve structure problem

Hi! ๐Ÿ‘‹

Firstly, thanks for your work on this project! ๐Ÿ™‚

Today I used patch-package to patch [email protected] for the project I'm working on.

Here is the diff that solved my problem:

diff --git a/node_modules/dbf/src/structure.js b/node_modules/dbf/src/structure.js
index 4b02783..f2b4c0b 100644
--- a/node_modules/dbf/src/structure.js
+++ b/node_modules/dbf/src/structure.js
@@ -55,7 +55,7 @@ module.exports = function structure(data, meta) {
         if (f.type == 'N') view.setInt8(32 + i * 32 + 17, 3);
     });
 
-    offset = fieldDescLength + 32;
+    var offset = fieldDescLength + 32;
 
     data.forEach(function(row, num) {
         // delete flag: this is not deleted

This issue body was partially generated by patch-package.

Shapefile export-import workflow

I'm working on a project that allows export of drawn geometries as shapefile and import of shapefiles for presentation on the map.

Right now I'm trying to implement the workflow when you can draw a feature, export it as shapefile, drag'n'drop it on the page again and it will be imported.

For shapefile export I'm using shp-write library, which is dependent on your lib, and shapefile-js for import. When the latter is trying to parse dbf file created by your library, I receive "Offset is outside the bounds of the DataView" in latest Chrome (there must be at least one property present for the feature in geojson, but it's another bug).

I have tried to open exported shapefile in QGIS and save it again, then shapefile-js library has no troubles parsing the created dbf. So I guess there's some difference between the dbf created by javascript vs. dbf created by QGIS. Any ideas where the bug might be?

'offset' is not defined

I'm get the error 'offset' is not defined because I use strict mode. I saw that code is fixed for it but still not published it because whenever I'm download npm package "npm i dbf". I'm able to reproduce this issue and found that the code is not updated in npm package side. Still "var" is missing in line number 58

https://www.npmjs.com/package/dbf?activeTab=code
image

Streaming?

It's possible but a little zany to implement this with streams rather than pre-allocating buffers

offset not defined, throws error in 'use strict' mode

Because offset is not declared with var in structure.js, this package breaks if you try to bundle it with something like rollup and you have 'use strict'. The workaround is that you can tell rollup to not 'use strict' but it's probably better that variables are declared.

Append data to existing file

Hi.

Is it possible to append data (instead of replacing the old file) to an existing DBF file? I tried to use fs methods such appendFileSync or writeSync instead of writeFileSync; and the file updates its date and size, but I can't see new data... only the first registers I added using writeSync.

Thank you very much.

chinese character

when i open the dbf file, ithe chinese character is messy code, how to solve the problem? thank you

Field header truncated

Hi,

Thanks for your tool. Perhaps I am wrong, but I think the field headers should allow up to 10 characters. I try to export with such but I get headers truncated at 8

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.