const watchFileCreated = (filename) => new Promise((resolve, reject) => { const TIMEOUT = 800 const INTERVAL = 100 const threshold = TIMEOUT / INTERVAL let counter = 0 const interval = setInterval(() => { // On some CI runs file is created but not filled if (existsSync(filename) && statSync(filename).size !== 0) { clearInterval(interval) resolve() } else if (counter <= threshold) { counter++ } else { clearInterval(interval) reject(new Error(`${filename} was not created.`)) } }, INTERVAL) })
broker.createService({ name: "file", actions: { get(ctx) { const fileName = "d:/src.zip"; const stat = fs.statSync(fileName); let uploadedSize = 0; const stream = fs.createReadStream(fileName); stream.on("data", chunk => { uploadedSize += chunk.length; this.logger.info("SEND: ", Number(uploadedSize / stat.size * 100).toFixed(0) + `% (${chunk.length})`); }); stream.on("close", () => { getSHA(fileName).then(hash => { broker.logger.info("File sent."); broker.logger.info("SHA:", hash); broker.logger.info("Size:", stat.size); }); }); return stream; } } });
broker.logger.info("RECV: ", Number(uploadedSize / stat.size * 100).toFixed(0) + `% (${chunk.length})`); });
size: stats.size, }, next,
lecture_name + ".mtd" ).size ) { dl = downloader.download(
const genUploadResult = (fileName, filePath) => { const fileStat = fs.statSync(filePath); const fileBuffer = fs.readFileSync(filePath); return { name: fileName, md5: md5(fileBuffer), size: fileStat.size, uploadDir: '', uploadPath: '' }; }
"node-file", name, info.size, info.mtime.getTime(), options.endpoint
name: expectedFileNameOnFileSystem, md5: fileHash, size: fileStat.size, uploadDir: '', uploadPath: ''
var createFileSync = function (filePath, size) { if (!fs.existsSync(filePath) || fs.statSync(filePath).size !== size) { fs.writeFileSync(filePath, Buffer.from(Array(size).fill(0))); } return filePath; }
function getImageDownloadProgress (info, callback) { var imgPath = persistance.getImagePath(info) fs.stat(imgPath, (err, stat) => { if (err) { return callback(err) } callback(null, stat.size / info.totalSize) }) /** fs.stat */ }
constructor({appId, filePath}) { this.appId = appId this.filePath = filePath this.fileLen = fs.statSync(this.filePath).size this.fileName = path.basename(this.filePath) }
describe('buffer', () => { it('response', async () => { var {body} = await Response.buffer()({ res: fs.createReadStream(file.binary, {highWaterMark: 1024}), }) t.equal( fs.statSync(file.binary).size, body.length, 'should return the raw buffer' ) }) })
function getFilesizeInBytes(filename) { const stats = fs.statSync(filename) const fileSizeInBytes = stats.size return fileSizeInBytes }