Skip to content

Commit

Permalink
Receives tarred rust binary and runs proper command to execute
Browse files Browse the repository at this point in the history
  • Loading branch information
johnnyman727 committed Jul 13, 2016
1 parent 48e4c75 commit de6f0b2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 26 deletions.
2 changes: 1 addition & 1 deletion lib/tessel/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ module.exports.js = {
};

module.exports.rs = {
execute: () => [rust.exports.meta.binary],
execute: () => [rust.meta.binary],
};

module.exports.py = {
Expand Down
31 changes: 6 additions & 25 deletions lib/tessel/deployment/rust.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ var exportables = {
meta: {
name: 'rust',
extname: 'rs',
binary: 'rust_executable',
// TODO: do not hardcode the binary name
binary: '/tmp/remote-script/hello',
// TODO: do not hardcode the entry
entry: 'src/main.rs',
configuration: 'Cargo.toml',
checkConfiguration: (pushdir, basename, program) => {
Expand Down Expand Up @@ -107,42 +109,21 @@ exportables.remoteRustCompilation = function(opts) {
}
};

// Create a new tar pack for incoming executable data
var pack = tarStream.pack();
// Create the entry file name
var entry = pack.entry({
name: exportables.meta.binary
});

// Set up the request
var post_req = http.request(post_options, function(res) {
// When we get incoming binary data, save to our buffers
res.on('data', function(chunk) {
// Write this incoming data to our tar packer
entry.write(chunk);
buffers.push(chunk);
})
// Reject on failure
.on('error', function(e) {
return reject(e);
})
// When the post completes, resolve with the executable
.on('end', function() {
// Indicate that all data has been received
pack.finalize();

// Turn the stream into an array of buffers
return streamToArray(pack)
.then((arr) => {
// For each buffer in the array
for (var i = 0, l = arr.length; i < l; ++i) {
// Grab the part
var part = parts[i];
// Push it into our buffer array
buffers.push((part instanceof Buffer) ? part : new Buffer(part));
}
// Resolve with concatenated buffers
return resolve(Buffer.concat(buffers));
});
// Resolve with concatenated buffers
return resolve(Buffer.concat(buffers));
});
});

Expand Down

0 comments on commit de6f0b2

Please sign in to comment.