Created
May 24, 2017 00:54
-
-
Save mhkeller/2d3cda87052ad8bf82c9039664bcefab to your computer and use it in GitHub Desktop.
broken dbf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<body> | |
<script src="https://wzrd.in/standalone/buffer"></script> | |
<script src="https://unpkg.com/dbf@latest/dbf.js"></script> | |
<script src="index.js"></script> | |
<h2 style="font-family:Helvetica;">Click this to download a broken dbf</h2> | |
<button onclick="downloadDbf()">download</button> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// var dbf = require('dbf') | |
// var fs = require('fs') | |
var buf = dbf.structure([ | |
{foo: 'bar', noo: 10}, | |
{foo: 'louie'} | |
]) | |
function toBuffer (ab) { | |
var buf = new buffer.Buffer(ab.byteLength) | |
var view = new Uint8Array(ab) | |
for (var i = 0; i < buf.length; ++i) { | |
buf[i] = view[i] | |
} | |
return buf | |
} | |
/* In Node, this works fine */ | |
// fs.writeFileSync('foo.dbf', toBuffer(buf.buffer)); | |
/* In the browser, something like this doesn't work */ | |
var blob = new Blob(toBuffer(buf.buffer), {type: 'octet/stream'}) | |
var url = window.URL.createObjectURL(blob) | |
var a = document.createElement('a') | |
document.body.appendChild(a) | |
a.href = url | |
a.download = 'data.dbf' | |
function downloadDbf (){ | |
a.click() | |
console.log('here') | |
window.URL.revokeObjectURL(url) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment