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.on('upload', ({ name, data }) => {
const amount = Buffer.byteLength(data);
const amount = data.length;
if (debug) {
console.log(`> [debug] Uploaded: ${name} (${bytes(Buffer.byteLength(data))})`);
console.log(`> [debug] Uploaded: ${name} (${bytes(data.length)})`);
}
bar.tick(amount);
});

2
lib/hash.js

@ -10,7 +10,7 @@ import { readFile } from 'fs-promise';
export default async function hashes (files) {
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 new Map(entries);

22
lib/index.js

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

1
package.json

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

Loading…
Cancel
Save