|
|
@ -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; |
|
|
|