Created
July 25, 2013 22:51
-
-
Save chrisgervang/6084478 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
fs = Meteor.require('fs'); | |
Future = Meteor.require('fibers/future'); | |
Meteor.methods({ | |
loadCSV: function() { | |
console.log('loadCSV called'); | |
// Set up a future for the current job | |
var future = new Future(); | |
//array of data to return to client | |
var assetsList = []; | |
//Make async fs call | |
fs.readFile('./public/assetNames.csv', 'utf8', function(err, data) { | |
if (err) { | |
console.log('load error: ',err); | |
} else { | |
data = data.split(/\n/); | |
//console.log(data, 'read complete'); | |
for (var i = 0; i < data.length; i++) { | |
var asset = data[i].split(/,/); | |
asset[1] = asset[1].replace(/\"/g,''); | |
if(!(asset[1].match(/\w+.png$/))) asset[1] += '.png'; | |
var assetType = asset[1].match(/[^Actor](.*?)(?=_)/)[0]; | |
console.log('image: ' + asset[1], 'handle: ' + asset[0], 'type: ' + assetType); | |
assetsList.push([asset[0],asset[1],assetType]); | |
} | |
} | |
console.log('in readFile:', assetsList); | |
future.ret(assetsList); | |
}); | |
// Return the future | |
return future.wait(); | |
} //end loadCSV | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment