Browse Source

Draft

master
Tony Kovanen 9 years ago
parent
commit
0e8ead93d2
  1. 4
      bin/now
  2. 2
      lib/hash.js
  3. 22
      lib/index.js
  4. 1
      package.json

4
bin/now

@ -111,9 +111,9 @@ async function sync (token) {
now.upload(); now.upload();
now.on('upload', ({ name, data }) => { now.on('upload', ({ name, data }) => {
const amount = Buffer.byteLength(data); const amount = data.length;
if (debug) { if (debug) {
console.log(`> [debug] Uploaded: ${name} (${bytes(Buffer.byteLength(data))})`); console.log(`> [debug] Uploaded: ${name} (${bytes(data.length)})`);
} }
bar.tick(amount); bar.tick(amount);
}); });

2
lib/hash.js

@ -10,7 +10,7 @@ import { readFile } from 'fs-promise';
export default async function hashes (files) { export default async function hashes (files) {
const entries = await Promise.all(files.map(async (name) => { const entries = await Promise.all(files.map(async (name) => {
const data = await readFile(name, 'utf8'); const data = await readFile(name);
return [hash(data), { name, data }]; return [hash(data), { name, data }];
})); }));
return new Map(entries); return new Map(entries);

22
lib/index.js

@ -6,6 +6,7 @@ import Agent from './agent';
import EventEmitter from 'events'; import EventEmitter from 'events';
import { basename, resolve } from 'path'; import { basename, resolve } from 'path';
import { stat, readFile } from 'fs-promise'; import { stat, readFile } from 'fs-promise';
import resumer from 'resumer';
// limit of size of files to find // limit of size of files to find
const ONEMB = bytes('1mb'); const ONEMB = bytes('1mb');
@ -67,7 +68,7 @@ export default class Now extends EventEmitter {
files: Array.from(this._files).map(([sha, { data, name }]) => { files: Array.from(this._files).map(([sha, { data, name }]) => {
return { return {
sha, sha,
size: Buffer.byteLength(data), size: data.length,
file: toRelative(name, this._path) file: toRelative(name, this._path)
}; };
}) })
@ -103,14 +104,19 @@ export default class Now extends EventEmitter {
const { data, name } = file; const { data, name } = file;
if (this._debug) console.time(`> [debug] /sync ${name}`); if (this._debug) console.time(`> [debug] /sync ${name}`);
const stream = resumer().queue(data).end();
const res = await this._fetch('/sync', { const res = await this._fetch('/sync', {
method: 'POST', method: 'POST',
body: { headers: {
sha, 'Content-Type': 'application/octet-stream',
data: data.toString(), 'Content-Length': data.length,
file: toRelative(name, this._path), 'x-now-deployment-id': this._id,
deploymentId: this._id 'x-now-sha': sha,
} 'x-now-file': toRelative(name, this._path),
'x-now-size': data.length
},
body: stream
}); });
if (this._debug) console.timeEnd(`> [debug] /sync ${name}`); if (this._debug) console.timeEnd(`> [debug] /sync ${name}`);
@ -143,7 +149,7 @@ export default class Now extends EventEmitter {
get syncAmount () { get syncAmount () {
if (!this._syncAmount) { if (!this._syncAmount) {
this._syncAmount = this._missing this._syncAmount = this._missing
.map((sha) => Buffer.byteLength(this._files.get(sha).data)) .map((sha) => this._files.get(sha).data.length)
.reduce((a, b) => a + b, 0); .reduce((a, b) => a + b, 0);
} }
return this._syncAmount; return this._syncAmount;

1
package.json

@ -23,6 +23,7 @@
"ms": "0.7.1", "ms": "0.7.1",
"node-fetch": "1.3.3", "node-fetch": "1.3.3",
"progress": "1.1.8", "progress": "1.1.8",
"resumer": "0.0.0",
"retry": "0.9.0", "retry": "0.9.0",
"spdy": "3.2.3" "spdy": "3.2.3"
}, },

Loading…
Cancel
Save