Skip to content

Instantly share code, notes, and snippets.

@mk-pmb
Created March 13, 2015 16:44
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mk-pmb/0b9105e4934e8499eca2 to your computer and use it in GitHub Desktop.
Save mk-pmb/0b9105e4934e8499eca2 to your computer and use it in GitHub Desktop.
Node.js tests for ISO umlauts in filenames
#!/usr/bin/perl
use strict;
open(GROSZ, ">>", "test-uml\xE4\xFCt\xDF-file.txt");
close(GROSZ);
/* -*- coding: UTF-8, tab-width: 2 -*- */
/*jslint indent: 2, maxlen: 80, node: true */
'use strict';
var fs = require('fs'), encs;
encs = {
bin: 'binary',
latinWest: 'ISO-8859-1',
latinEuro: 'ISO-8859-15',
};
function report(err, data) { console.dir(err || data); }
fs.readdir('.', function (readDirErr, filesList) {
var umlFname, umlPart, umlBuf;
if (readDirErr) { return console.error(readDirErr); }
umlFname = filesList.filter(/x/.test.bind(/^test-uml/))[0];
console.log('umlauts filename:', umlFname);
umlPart = umlFname.replace(/^[a-z\.\-]+/, '').replace(/[a-z\.\-]+$/, '');
console.log('umlauts part only:', umlPart);
umlBuf = new Buffer(umlPart, encs.bin);
console.log('umlauts part as buffer:', umlBuf);
fs.readFile(umlFname, report);
fs.readFile('test-umläutß-file.txt', report);
fs.readFile('test-uml\xe4\xfct\xdf-file.txt', report);
console.log('U+00e4 in UTF-8 bytes:', new Buffer('\xe4', 'UTF-8'));
console.log('U+00e4 in UCS-2 bytes:', new Buffer('\xe4', 'UCS-2'));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment