Created
March 13, 2015 16:44
-
-
Save mk-pmb/0b9105e4934e8499eca2 to your computer and use it in GitHub Desktop.
Node.js tests for ISO umlauts in filenames
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
#!/usr/bin/perl | |
use strict; | |
open(GROSZ, ">>", "test-uml\xE4\xFCt\xDF-file.txt"); | |
close(GROSZ); |
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
/* -*- 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