Skip to content

Instantly share code, notes, and snippets.

@phochste
Created April 30, 2015 08:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phochste/fac239564a38f8c2eb8a to your computer and use it in GitHub Desktop.
Save phochste/fac239564a38f8c2eb8a to your computer and use it in GitHub Desktop.
#!/usr/bin/env node
/*
* Install: npm install n3
* Usage: cat gigantic.ttl | tutle2ntriples
* Usage: tutle2ntriples gigantic.ttl
*
* See also: https://github.com/RubenVerborgh/N3.js
*/
var file = undefined;
if (process.argv.length == 2) {
file = '/dev/stdin';
}
else {
file = process.argv[2];
}
var N3 = require('n3');
var fs = require('fs');
var streamParser = new N3.StreamParser(),
inputStream = fs.createReadStream(file),
streamWriter = new N3.StreamWriter({ format: 'N-Triples' });
inputStream.pipe(streamParser);
streamParser.pipe(streamWriter);
streamWriter.pipe(process.stdout);
@RubenVerborgh
Copy link

I thought that, as a Perl programmer, you might like to know that you could even save some lines by var file = process.argv[2] || '/dev/stdin' 😉

@phochste
Copy link
Author

hehehe

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment