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
var readline = require('readline'); | |
var Client = require('ftp'); | |
var fs = require('fs'); | |
const { exec } = require('child_process'); | |
var ready = false; | |
var c = new Client(); | |
c.on('ready', function() { | |
ready = true; | |
}); |
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
var fs = require('fs'); | |
var portAudio = require('naudiodon'); | |
// デバイスのオープン | |
var ai = new portAudio.AudioIO({ | |
inOptions: { | |
channelCount: 1, | |
sampleFormat: portAudio.SampleFormat16Bit, | |
sampleRate: 44100, | |
deviceId: 6, // ここは環境によって書き換える必要あり |
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
var fs = require('fs'); | |
var doSomethingWithTheStream = require('./dosomething'); | |
// readable streamはcreateReadStream関数がインスタンス化する | |
var readable = fs.createReadStream('image.jpg'); | |
var totalBytes = 0; | |
// readableのメンバー関数read()をProxyで置き換え | |
readable.read = new Proxy(readable.read, { |
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
// readableを使って「何か」をする関数の本体 | |
module.exports = function doSomethingWithTheStream(readable) { | |
return new Promise(function(resolve, reject){ | |
var count = 0; | |
readable.on('readable', () => { | |
// 読み取り | |
var data; | |
while (data = readable.read()) { | |
// ここで読み取った部分的なデータ(chunk)を処理する... |
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
var fs = require('fs'); | |
var doSomethingWithTheStream = require('./dosomething'); | |
// readable streamはcreateReadStream関数がインスタンス化する | |
var readable = fs.createReadStream('image.jpg'); | |
// 「何か」をする関数にオブジェクトを渡す | |
doSomethingWithTheStream(readable).then(() => { | |
console.log('All done!'); | |
}); |
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
// 元の関数を定義 | |
function showtime(season) { | |
console.log(`トムとジェリーのシーズン ${season}をみる`); | |
} | |
// 元の関数を呼び出し | |
showtime(1); | |
showtime(2); | |
showtime(3); |
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
// トムという名前を持った犬オブジェクトを生成 | |
var dog = {name: 'トム', age: 1}; | |
// 1. 普通に dog を使う | |
console.log(`${dog.name}は、${dog.age} 歳の犬です`); | |
// Proxyに渡すhandler | |
var handler = { | |
get: (target, prop, receiver) => { |
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
// console.logを置き換えて、 | |
// 出力の先頭に '(xxxxxxx)'のように現在の時間を表示する | |
console.log = new Proxy(console.log, { | |
apply: function(target, thisArg, argList) { | |
var n = Date.now(); | |
argList[0] = '(' + n + ') ' + argList[0]; | |
return target.apply(thisArg, argList); | |
} | |
}) |