AngularJSã¨RequireJSãåããã¦ä½¿ã£ã¦ã¿ã
ã¢ã¸ã¥ã¼ã«åä½ã§ãã¡ã¤ã«ã«åãããããªã¼ã¨æã£ãã®ã§ã
AngularJSæ¬å®¶ã®ãã¥ã¼ããªã¢ã«ã®phonecatAppãé¡æã«ãã¦ã
AngularJS + RequireJS | StarterSquadãåèã«ã¡ãã£ã¨ã¢ã¬ã³ã¸ã
çµæã®ã½ã¼ã¹ã¯こちら
åä½ãã¹ãã®å®è¡ã¨çµåããã½ã¼ã¹ãproduction.htmlã§è¦ããã¨ããã¾ã§ç¢ºèªã
ã¢ããªã®å®ç¾©
phonecatApp.controllersã«ã¯PhoneListCtrlã¨PhoneDetailCtrlãå
¥ã£ã¦ãã
phonecatApp.filtersã«ã¯checkmarkã
phonecatApp.servicesã«ã¯Phoneãããããå
¥ã£ã¦ãã
app/assets/js/app.js
define([ 'angular', 'angularRoute', 'angularResource', './services/Phone', './filters/checkmark', './controllers/PhoneListCtrl', './controllers/PhoneDetailCtrl' ], function(angular) { 'use strict'; var phonecatApp = angular.module('phonecatApp', [ 'ngRoute', 'phonecatApp.controllers', 'phonecatApp.filters', 'phonecatApp.services' ]); phonecatApp.config([ '$routeProvider', function($routeProvider) { $routeProvider. when('/phones', { templateUrl: 'assets/js/templates/phone-list.html', controller: 'PhoneListCtrl' }). when('/phones/:phoneId', { templateUrl: 'assets/js/templates/phone-detail.html', controller: 'PhoneDetailCtrl' }). otherwise({ redirectTo: '/phones' }); } ]); return phonecatApp; });
ã¢ã¸ã¥ã¼ã«å®ç¾©ï¼ä¾ï¼ã³ã³ããã¼ã©ï¼
ä¾åé¢ä¿ã§èªã¿è¾¼ãã§ããmoduleï¼app/assets/js/controllers/module.jsï¼ããã¤ã³ãã«ãªãã
app/assets/js/controllers/PhoneListCtrl.js
define([ './module', '../services/Phone' ], function(controllers) { 'use strict'; return controllers.controller('PhoneListCtrl', [ '$scope', 'Phone', function($scope, Phone) { $scope.phones = Phone.query(); $scope.orderProp = 'age'; } ]); });
moduleã§phonecatApp.controllersãå®ç¾©ãã¦ã³ã³ããã¼ã©ãç»é²ãããã
servicesã¨ããä¼¼ããããªæãã§åã¾ã¨ã¾ãã§moduleä½ã£ã¦ããã«ç»é²ãããã
app/assets/js/controllers/module.js
define([ 'angular', ], function(ng) { 'use strict'; return ng.module('phonecatApp.controllers', []); });
ã¢ããªã®èµ·å
ng-appãã£ã¬ã¯ãã£ãã ã¨éã«åããªãã®ã§ãangular.bootstrapã使ã£ã¦æåã§phonecatAppãå®è¡ããã
app/assets/js/bootstrap.js
require([ 'angular', 'app' ], function(ng) { 'use strict'; ng.bootstrap(document, ['phonecatApp']); });
ææ³
defineãrequireã¨angular.module両æ¹ã§ä¾åå®ç¾©ããå¿
è¦ãããã®ã§ãã¡ãã£ã¨å¾®å¦ã
mongooseã§åãè¾¼ã¿ã使ã
MongoDBã®ãªã¬ã¼ã·ã§ã³ã§ãããåãè¾¼ã¿ã§ãããè¿·ã£ãæ«ã«åãè¾¼ã¿ã§ãããã¨ã«ããã®ã§ã
mongooseã§ã®ããæ¹ããã£ã¨è©¦ãã¦ã¿ãã
使ã£ããã¼ã¸ã§ã³
node.js v0.8.18
mongoose 3.5.5
試é¨ã½ã¼ã¹
ã³ã¼ã«ããã¯ã ããã«ãªãã®ã§ãjsdeferred使ã£ã¦æµãæ´çããã
var Deferred = require('./deps/jsdeferred').Deferred, // mongoose mongoose = require('mongoose'), // åã¹ãã¼ã ChildSchema = new mongoose.Schema({ name : String }), // 親ã¹ãã¼ã ParentSchema = new mongoose.Schema({ name : String, childlen : [ChildSchema] }), // 親ã¢ãã« Parent = mongoose.model('Parent', ParentSchema); // æ¥ç¶ mongoose.connect('mongodb://localhost/foo'); !function() { // æåã«db.parentsãå ¨é¨æ¶ãã¦ãã var d = new Deferred(); Parent.remove(function(err) { if (err) { d.fail(err); return; } d.call(); }); return d; }() .next(function() { var d = new Deferred(), // parentãæ°è¦ä½æãã¦ä¿å parent = new Parent({ name : 'test' }); parent.save(function(err) { if (err) { d.fail(err); return; } d.call(); }); return d; }) .next(function() { var d = new Deferred(); // 親ãåå¾ Parent.findOne({ name : 'test'}, function(err, parent) { if (err) { d.fail(err); return; } // 親ã®ååããã§ã㯠console.log(parent.name); console.log('åä¾ã0人'); // ãã®æç¹ã§ã¯ã¾ã åä¾ãããªã console.log(parent.childlen); // åä¾ãä¸äººè¿½å parent.childlen.push({ name : 'baby1' }); parent.save(function(err) { if (err) { d.fail(err); } d.call(); }); }); return d; }) .next(function() { var d = new Deferred(); // 親ãåå¾ Parent.findOne({ name : 'test'}, function(err, parent) { if (err) { d.fail(err); return; } console.log('åä¾ã1人'); console.log(parent.childlen); // ã¾ã¨ãã¦è¤æ°äººè¿½å parent.childlen.push({ name : 'baby2' }); parent.childlen.push({ name : 'baby3' }); parent.childlen.push({ name : 'baby4' }); parent.save(function(err) { if (err) { d.fail(err); } d.call(); }); }); return d; }) .next(function() { var d = new Deferred(); // 親ãåå¾ Parent.findOne({ name : 'test'}, function(err, parent) { if (err) { d.fail(err); return; } console.log('åä¾ã4人'); console.log(parent.childlen); // ååãæ´æ°ãã parent.childlen[0].name = 'John'; parent.childlen[1].name = 'Paul'; parent.childlen[2].name = 'George'; parent.childlen[3].name = 'Ringo'; parent.save(function(err) { if (err) { d.fail(err); } d.call(); }); }); return d; }) .next(function() { var d = new Deferred(); // 親ãåå¾ Parent.findOne({ name : 'test'}, function(err, parent) { if (err) { d.fail(err); return; } console.log('æ´æ°å¾'); console.log(parent.childlen); // 1ã¤åé¤ parent.childlen.remove(parent.childlen[1]); parent.save(function(err) { if (err) { d.fail(err); } d.call(); }); }); return d; }) .next(function() { var d = new Deferred(); // 親ãåå¾ Parent.findOne({ name : 'test'}, function(err, parent) { if (err) { d.fail(err); return; } console.log('1件åé¤å¾'); console.log(parent.childlen); // å ¨ã¦åé¤ãã /** * forEachã ã¨ãã¾ãæ¶ããªã */ // parent.childlen.forEach(function(c) { // c.remove(); // }); var i, len = parent.childlen.length; for (i = len - 1; i >= 0; i--) { parent.childlen[i].remove(); } parent.save(function(err) { if (err) { d.fail(err); } d.call(); }); }); return d; }) .next(function() { var d = new Deferred(); // 親ãåå¾ Parent.findOne({ name : 'test'}, function(err, parent) { if (err) { d.fail(err); return; } console.log('0人'); console.log(parent.childlen); d.call(); }); return d; }) .next(function() { mongoose.disconnect(); }) .error(function(err) { console.log(err); mongoose.disconnect(); });
å®è¡çµæ
$ node index test åä¾ã0人 [] åä¾ã1人 [{ name: 'baby1', _id: 51110eba0d42bc5711000003 }] åä¾ã4人 [{ name: 'baby1', _id: 51110eba0d42bc5711000003 } { name: 'baby2', _id: 51110eba0d42bc5711000004 } { name: 'baby3', _id: 51110eba0d42bc5711000005 } { name: 'baby4', _id: 51110eba0d42bc5711000006 }] æ´æ°å¾ [{ _id: 51110eba0d42bc5711000003, name: 'John' } { _id: 51110eba0d42bc5711000004, name: 'Paul' } { _id: 51110eba0d42bc5711000005, name: 'George' } { _id: 51110eba0d42bc5711000006, name: 'Ringo' }] 1件åé¤å¾ [{ _id: 51110eba0d42bc5711000003, name: 'John' } { _id: 51110eba0d42bc5711000005, name: 'George' } { _id: 51110eba0d42bc5711000006, name: 'Ringo' }] 0人 []
ææ³
åé¤ã®æã«forEachã§åãã¨ã¤ã³ããã¯ã¹ã®é¢ä¿ãåé¤ãã¾ããããªãã¿ããã
expressã§ãã©ã¼ã ãããã¡ã¤ã«ã¢ãããã¼ããã
node.jsã§express使ã£ã¦ãã©ã¼ã ã®ãã¡ã¤ã«ã¢ãããã¼ãããå ´åã
bodyParser使ã£ã¦ããã°requestã®filesããåå¾ã§ããæ§åã
å®é¨ã³ã¼ã
HTMLã¯ãããªæãã
<!DOCTYPE HTML> <html lang="en"> <head> <meta charset="UTF-8"> <title>Study</title> </head> <body> <div> <h3>File Upload</h3> <!-- ãã¡ã¤ã«ã¢ãããã¼ããã©ã¼ã --> <form id="file-form" method="post" action="/postdata" enctype="multipart/form-data"> <input type="file" name="image_file" /> <button type="submit" class="btn">Submit</button> </form> <h3>Uploaded File</h3> <!-- åã«ã¢ãããã¼ããããã¡ã¤ã« --> <img src="./img/upfile.png" /> </div> </body> </html>
ãµã¼ãå´ã®ã½ã¼ã¹ãããªæãã
var express = require('express'), fs = require('fs'), imageDirPath = __dirname + '/webroot/img/', app = express(); app.use(express.static(__dirname + '/webroot')); app.use(express.bodyParser()); app.post('/postdata', function(req, res) { // fileãªãã¸ã§ã¯ãåå¾ var file = req.files.image_file; // ãªãã¼ã ãã¦imgã¿ã°ã§è¦ããããã«ãã fs.rename(file.path, imageDirPath + 'upfile.png' , function(err) { if (err) { console.log(err); } // ãªãã¤ã¬ã¯ãã§æ»ã res.set('Location', '/'); res.send(301); }); }); app.listen(8080);
è£è¶³
bodyParserã«ãã©ã¡ã¼ã¿æ¸¡ãã¨ãä¸æãã¡ã¤ã«ã§æ¡å¼µåãç¶æããã¨ããä¸æãã¡ã¤ã«ã®ä¿åãã£ã¬ã¯ããªãæå®ã§ããã
app.use(express.bodyParser({ keepExtensions: true, uploadDir: '/my/files' }));
node-mysqlã§TEXTå使ã£ã¦ããæååããã
node-mysqlã®0.9.6ã使ã£ã¦ããããTEXTåã®ã«ã©ã ã®ãã¼ã¿ãæã
æååãããç¾è±¡ã«åºããããã
node-mysqlã¯JavaScriptã ãã§å
¨é¨ã§ãã¦ãã®ã§ãã½ã¼ã¹ã追ã£ã¦èª¿ã¹ã¦ã¿ãã
調æ»
mysql/lib/query.jsã«
row[field.name] += buffer.toString('utf-8');
ã¨ãªã£ã¦ãã¦ãBufferãUTF-8ã®æååã«ãã¦ããé£çµãã¦ããé¨åãçºè¦ããããæªããã
対å¿
Bufferããã£ããä¿æãã¦ããã¦ãæçµçã«é£çµãã¦æåååããããã«å¤æ´ãã¦ã¿ãã
以ä¸ãå·®åã
5a6,19 > function joinBuffers(buffers) { > var i, len = buffers.length, size = 0; > for (i = 0; i < len; i++) { > size += buffers[i].length; > } > var result = new Buffer(size); > var buffer, from = 0; > while (buffer = buffers.shift()) { > buffer.copy(result, from, 0); > from += buffer.length; > } > return result; > } > 62c76 < row[field.name] = ''; --- > row[field.name] = []; 66,68c80 < row[field.name] += buffer.toString('utf-8'); < } else { < row[field.name] = null; --- > row[field.name].push(buffer); 72a85,90 > } > > if (row[field.name].length > 0) { > row[field.name] = joinBuffers(row[field.name]).toString('utf-8'); > } else { > row[field.name] = null;
çµæ
解決ããã£ã½ããæååãããªããªã£ãã
githubã§forkãã¦ä¿®æ£ãpull requestæãã¦ã¿ãããã¨æã£ããã©ã
ãªããéçºé²ãã§ã ãã¶æ§å¤ãããã¦ãã¿ãããªã®ã§ããã£ã¨ãã©ã¦ã¶ãéããã
WebSocketã§ãã¤ããªãéåä¿¡ãã¦ã¿ã(2)
ã¯ã©ã¤ã¢ã³ããããã¤ããªãéã確èªãã§ããã®ã§ã
ãã¤ããªã«æ´ã«ãã¼ã¿ä¹ã£ãã¦éã£ããããã£ãããã¦ã¿ãã
ã¯ã©ã¤ã¢ã³ãå´
input:fileã§ãã¡ã¤ã«ãåç
§ããããå
é ã«helloworldæååã追å ãã
ãã¤ããªãã¼ã¿ã¨ãã¦éä¿¡ããã
ãµã¼ãå´ããã¡ãã»ã¼ã¸ãåãåã£ã¦ããã¤ããªãã¼ã¿ã ã£ãã
å
é ã®æååã¨ç»åãã¼ã¿ã«åãã¦ãããã表示ããã
// BlobBuilder BlobBuilder = window.BlobBuilder || window.WebKitBlobBuilder || window.MozBlobBuilder; // URL URL = window.URL || window.webkitURL; // document var doc = document; // WebSocketãéã var socket = new WebSocket('ws://' + location.host); // ãã¤ããªãã¼ã¿ã¯ArrayBufferã§åå¾ãã socket.binaryType = 'arraybuffer'; // messageã¤ãã³ã socket.addEventListener('message', function(evt) { var data = evt.data; if (data.constructor === String) { // Stringã®å ´åãpã¿ã°ã§è¿½å var p = doc.createElement('p'); p.textContent = data; doc.getElementById('messages').appendChild(p); } else if (data.constructor === ArrayBuffer) { // ArrayBufferã®å ´åãä»å ãããæååã¨ç»åãã¼ã¿ã«åãã // å é ãã10ãã¤ãã8ããã符å·ãªãæ´æ°å¤ã®é åã« var arr = new Uint8Array(data.slice(0, 10)); var key = []; for (var i = 0; i < 10; i++) { // ãã£ã©ã¯ã¿ã³ã¼ãã§æååã«å¤æãã¦æ ¼ç´ key.push(String.fromCharCode(arr[i])); } // ä»å ããæååãpã¿ã°ã§è¿½å var p = doc.createElement('p'); p.textContent = key.join(''); doc.getElementById('messages').appendChild(p); // ç»åãã¼ã¿åãimgã¿ã°ã§è¿½å var builder = new BlobBuilder(); var img = new Image(); builder.append(data.slice(10)); img.src = URL.createObjectURL(builder.getBlob()); doc.getElementById('images').appendChild(img); } else { alert('nanigashi'); } }, false); // æååãã¼ã¿ããµã¼ãã«éä¿¡ doc.getElementById('sendText') .addEventListener('click', function(evt) { socket.send('test'); }, false); // fileãåç §ããããµã¼ãã«éä¿¡ doc.getElementById('image') .addEventListener('change', function(evt) { var file = evt.target.files[0]; var builder = new BlobBuilder(); builder.append('helloworld'); builder.append(file); // socket.send(file); socket.send(builder.getBlob()); }, false);
ãµã¼ãå´
ã¯ã©ã¤ã¢ã³ããããã¤ããªãã¼ã¿ãåãåã£ããæååã¨ç»åãã¼ã¿ã«å解ãã¦ã
æååãè¿ãããã¨ã«æ°ããªæååãå
é ã«ãã£ã¤ããç»åãã¼ã¿ãéä¿¡ããã
// http server var connect = require('connect'); var httpServer = connect() .use(connect.static(__dirname + '/webroot')) .listen(1234); // WebSocket Server var WebSocketServer = require('websocket').server; var wsServer = new WebSocketServer({ httpServer : httpServer, autoAcceptConnections : true }); // ã¯ã©ã¤ã¢ã³ãæ¥ç¶ã¤ãã³ã wsServer.on('connect', function(client) { // ã¯ã©ã¤ã¢ã³ãããã®ã¡ãã»ã¼ã¸åä¿¡ã¤ãã³ã client.on('message', function(message) { if (message.type === 'utf8') { // æååã ã£ããæååã¨ãã¦ãã®ã¾ã¾éä¿¡ client.sendUTF(message.utf8Data); } else if (message.type === 'binary') { // ãã¤ããªã ã£ããä»å ããã¦ããæååãåãåºã var src = message.binaryData; var text = new Buffer(10); src.copy(text, 0, 0, 10); // åãåã£ãæååãè¿ã client.sendUTF('receive:' + text.toString('utf8')); // æ°ããªæååãä»å ãã¦æ¸ãæãããã¤ããªãã¼ã¿ã¨ãã¦éä¿¡ var str = 'helloagain'; var key = new Buffer(str); var buf = new Buffer(src.length); key.copy(buf, 0); src.copy(buf, 10, 10); client.sendBytes(buf); } else { console.log('nanigashi'); } }); });
çµæ
ArrayBufferã使ã£ã¦ãããããããã¨ã§ããã¤ããªãã¼ã¿ãåå²ããããã¦
ããããã§ãããã¡ããã©Firefoxã12ããArrayBufferã®sliceãã§ããããã«ãªã£ã¦ãã
WebSocketã§ãã¤ããªãéåä¿¡ãã¦ã¿ã
Firefox11ã«ãªã£ã¦ã¨ã£ãã«WebSocketã®ãã³ãã¼ãã¬ãã£ãã¯ã¹ã¨ãã¦ããã
ãã¤ããªãã¼ã¿ã®éåä¿¡ã®è¾ºããã©ããªã£ã¦ãã確èªãã¦ã¿ãã
確èªãããã©ã¦ã¶ã¯Firefox11.0ã¨Google Chrome18.0.1025.162ã
ãµã¼ãå´
node.jsã§å®è£
ããã
httpãµã¼ãç¨ã«connectã使ã£ã¦ãWebSocketãµã¼ãã¯WebSocket-Nodeã使ãã
ããããnpm install connectãnpm install websocketã§ã¢ã¸ã¥ã¼ã«å ¥ããã
ãµã¼ãå´ã®ã³ã¼ãã¯æ¬¡ã®éãã
// http server var connect = require('connect'); var httpServer = connect() .use(connect.static(__dirname + '/webroot')) .listen(1234); // WebSocket Server var WebSocketServer = require('websocket').server; var wsServer = new WebSocketServer({ httpServer : httpServer, autoAcceptConnections : true }); // ã¯ã©ã¤ã¢ã³ãæ¥ç¶ã¤ãã³ã wsServer.on('connect', function(client) { // ã¯ã©ã¤ã¢ã³ãããã®ã¡ãã»ã¼ã¸åä¿¡ã¤ãã³ã client.on('message', function(message) { if (message.type === 'utf8') { // æååã ã£ããæååã¨ãã¦ãã®ã¾ã¾éä¿¡ client.sendUTF(message.utf8Data); } else if (message.type === 'binary') { // ãã¤ããªã ã£ãããã¤ããªã¨ãã¦ãã®ã¾ã¾éä¿¡ client.sendBytes(message.binaryData); } else { console.log('nanigashi'); } }); });
ã¯ã©ã¤ã¢ã³ãå´ããã¡ãã»ã¼ã¸å±ããããã¿ã¤ãã«å¿ãã¦ãã®ã¾ã¾è¿ãã ãã
ã¯ã©ã¤ã¢ã³ãå´
ãã¿ã³ãæ¼ãããåºå®æååãéãã®ã¨ããã¡ã¤ã«åç
§ããããããéãããã«ããã
éã£ããã¼ã¿ããµã¼ãããéãè¿ãããããã¿ã¤ãã«å¿ãã¦ããããã®divã®ä¸ã«æ¸ãã ãã
HTML次ã®ã¨ããã
<!DOCTYPE HTML> <html lang="en"> <head> <meta charset="UTF-8"> <title>WebSocket Test</title> </head> <body> <input id="sendText" type="button" value="æååãéã" /> <input id="image" name="image" type="file" /> <!-- æåååä¿¡ãã° --> <div id="messages"></div> <!-- ç»ååä¿¡ãã° --> <div id="images"></div> <script type="text/javascript" src="index.js"></script> </body> </html>
ã¯ã©ã¤ã¢ã³ãå´ã®JavaScriptã
// URL URL = window.URL || window.webkitURL; // document var doc = document; // WebSocketãéã var socket = new WebSocket('ws://' + location.host); // messageã¤ãã³ã socket.addEventListener('message', function(evt) { var data = evt.data; if (data.constructor === String) { // Stringã®å ´åãpã¿ã°ã§è¿½å var p = doc.createElement('p'); p.textContent = data; doc.getElementById('messages').appendChild(p); } else if (data.constructor === Blob) { // Blobã®å ´åãimgã¿ã°ã§è¿½å var img = new Image(); img.src = URL.createObjectURL(data); doc.getElementById('images').appendChild(img); } else { alert('nanigashi'); } }, false); // æååãã¼ã¿ããµã¼ãã«éä¿¡ doc.getElementById('sendText') .addEventListener('click', function(evt) { socket.send('test'); }, false); // fileãåç §ããããµã¼ãã«éä¿¡ doc.getElementById('image') .addEventListener('change', function(evt) { var file = evt.target.files[0]; socket.send(file); }, false);
çµæ
FirefoxãGoogle Chromeå
±ã«éã£ããã¤ããªãã¼ã¿ãéãè¿ãã¦ããã£ã¦è¡¨ç¤ºã§ããã
node-iconvã§EUCJP-WIN使ããã¨ãã¦ãããã ã
node.jsã¯utf-8ãåæãªã®ã§ãsjisã ã®eucã ã®ã¯å¤æãã¦ãããªãã¨ãã¡ã§ããã
ã¨ã®ãã¨ãªã®ã§ãæ±ãããã£ããã¼ã¿ãeucã ã£ãã®ã§ãnode-iconvãå
¥ãã¦å¤æãã¦ã¿ãã
node-iconvã®ã¤ã³ã¹ãã¼ã«ã¨å¤æå¦ç
npmã§å
¥ããã
$ npm install iconv
ãããªæãã§ä½¿ãã
/** * çç¥ */ // Iconv var Iconv = require('iconv').Iconv; // EUC to UTF-8ãªã³ã³ãã¼ã¿ãçæ var conv = new Iconv('EUC-JP', 'UTF-8//TRANSLIT//IGNORE'); // ãããã¡ãã³ã³ãã¼ããã¦UTF-8ãªãã¼ã¿ã«ãã var data = (conv.convert(buf)).toString('utf8'); /** * çç¥ */
æ©ç¨®ä¾åæåï¼ã ã£ãã£ãï¼ï¼ã«å¯¾å¿ããããªã£ã
ãã®ã¾ã§ãæ¦ãåé¡ãªããã ãã©ããã¼ãæ°åã¿ãããªã®ããã¡ã«ãªã£ã¡ããã®ã§ã
EUC-JPã®ä»£ããã«EUCJP-WINãæå®ãã¦ã//TRANSLIT//IGNOREãå¤ãã
ã§ãå®è¡ããããã¨ã©ã¼ã«ãªã£ãã
ã¨ã©ã¼ã¡ãã»ã¼ã¸ã
Error: EINVAL, Conversion not supported.
ãµãã¼ããã¦ãªããã£ã¦ãã¨ã£ã½ãã®ã§èª¿ã¹ã¦ã¿ãã
調æ»ã³ã¼ãã
var sys = require('sys'); var Iconv = require('iconv').Iconv; var charsets = [ 'EUC-JP-MS', 'EUC-JP', 'EUCJP-MS', 'EUCJP-OPEN', 'EUCJP-WIN', 'EUCJP' ]; var charset; while (charset = charsets.shift()) { try { new Iconv(charset, 'utf-8'); } catch(e) { sys.log('Fail : ' + charset); sys.log(e); } }
çµæã
$ node a.js 22 Apr 22:43:16 - Fail : EUC-JP-MS 22 Apr 22:43:16 - Error: EINVAL, Conversion not supported. 22 Apr 22:43:16 - Fail : EUCJP-MS 22 Apr 22:43:16 - Error: EINVAL, Conversion not supported. 22 Apr 22:43:16 - Fail : EUCJP-OPEN 22 Apr 22:43:16 - Error: EINVAL, Conversion not supported. 22 Apr 22:43:16 - Fail : EUCJP-WIN 22 Apr 22:43:16 - Error: EINVAL, Conversion not supported.
EUCJPã¨EUC-JPãããµãã¼ããã¦ãªã®ãã
ããããå½ã¦ãã
対å¿ãããããã«ãこちらã§å
¬éããã¦ããlibiconv-1.13-ja-1.patch.gzãå½ã¦ãã
node-iconvã®libiconvãã£ã¬ã¯ããªãããã¨ããã¾ã§ç§»åã
$ cd .node_libraries/.npm/iconv/1.1.0/package/deps/
ãããããã¦ã³ãã¼ãã
$ wget http://www2d.biglobe.ne.jp/~msyk/software/libiconv/libiconv-1.13-ja-1.patch.gz
libiconvã®ãã£ã¬ã¯ããªã«å
¥ã£ã¦ããããã¦ããæ¹ãã¦ãã«ãããã
$ cd libiconv-1.13.1/ $ gzip -dc ../libiconv-1.13-ja-1.patch.gz | patch -p1 $ ./configure --disable-shared --enable-static --enable-relocatable --enable-extra-encodings $ make
.node_libraries/.npm/iconv/1.1.0/packageã¾ã§ã¡ãã£ã¨æ»ã£ã¦ãnode-iconvã®ããããæ¹ãã¦ãã«ãããã
$ cd ../../ $ g++ -Ideps/libiconv-1.13.1/include -I/usr/local/include/node -O2 -fPIC -Wall -ansi -c -o iconv.o iconv.cc $ g++ -shared -o iconv.node iconv.o deps/libiconv-1.13.1/lib/.libs/libiconv.a
åä½ç¢ºèªã
ãã£ãã®ç¢ºèªã¹ã¯ãªãããããä¸åº¦å®è¡ããã
$ node a.js
ããã©ã¯OKã
å¤æå¦çã®æ¹ãå®è¡ãã¦ã¿ã¦ç¢ºèªã
/** * çç¥ */ // EUC to UTF-8ãªã³ã³ãã¼ã¿ãçæ var conv = new Iconv(EUCJP-WIN', 'UTF-8'); /** * çç¥ */
å¤æã§ããã