Reports compression implemented

dependabot/npm_and_yarn/BuildServer/eslint-7.2.0
Inga 🏳‍🌈 8 years ago
parent 8f1f4269ef
commit 6dba4b3201
  1. 34
      BuildServer/compress-old-reports.js
  2. 11
      BuildServer/lib/report-processor.js

@ -0,0 +1,34 @@
"use strict";
const fs = require("fs");
const path = require("path");
const zlib = require("zlib");
const glob = require("glob");
const async = require("async");
const settings = require("./settings");
glob("**\\report.json", { "cwd": settings.releasepath }, (globErr, files) => {
if (globErr) {
return console.log(globErr);
}
return async.parallelLimit(files.map((file) => (callback) => {
const originalPath = path.join(settings.releasepath, file);
const newPath = `${originalPath}.gz`;
console.log(file);
fs.createReadStream(originalPath)
.pipe(zlib.createGzip())
.pipe(fs.createWriteStream(newPath))
.on("error", callback)
.on("finish", () => {
fs.unlink(originalPath, callback);
});
}), 100, (err) => {
if (err) {
console.log(err);
}
console.log("Done");
});
});

@ -2,15 +2,19 @@
const path = require("path");
const fs = require("fs");
const zlib = require("zlib");
const glob = require("glob");
const streamBuffers = require("stream-buffers");
const _ = require("underscore");
const reportFilename = "report.json.gz";
const writeReport = (releaseDir, err, result, callback) => {
const readable = new streamBuffers.ReadableStreamBuffer();
readable
.pipe(fs.createWriteStream(path.join(releaseDir, "report.json")))
.pipe(zlib.createGzip())
.pipe(fs.createWriteStream(path.join(releaseDir, reportFilename)))
.on("error", callback)
.on("finish", callback);
@ -24,9 +28,10 @@ const writeReport = (releaseDir, err, result, callback) => {
const readReport = (releaseDir, callback) => {
const writable = new streamBuffers.WritableStreamBuffer();
const readStream = fs.createReadStream(path.join(releaseDir, "report.json"));
const readStream = fs.createReadStream(path.join(releaseDir, reportFilename));
readStream
.pipe(zlib.createGunzip())
.pipe(writable)
.on("error", callback)
.on("finish", () => {
@ -53,7 +58,7 @@ exports.loadReport = (app, options, callback) => {
return callback(err, options);
}
const reportFile = path.join(releaseDir, "report.json");
const reportFile = path.join(releaseDir, reportFilename);
options.files = files;

Loading…
Cancel
Save