Skip to content

Commit bfee1cc

Browse files
committed
New: Now compresses .gz files using zopfli to make them useful beyond being just a reference
1 parent aed134a commit bfee1cc

File tree

11 files changed

+56
-37
lines changed

11 files changed

+56
-37
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
[:hash:](https://github.com/dcodeIO/protobuf.js/commit/ea7ba8b83890084d61012cb5386dc11dadfb3908) Fixed release links in README files<br />
1717

1818
## New
19-
[:hash:](https://github.com/dcodeIO/protobuf.js/commit/9078a37fbf7bff8ba829d979073e3df91f1bcfc5) Updated non-bundled common google types folder with field_mask, source_context, type and wrappers<br />
19+
[:hash:](https://github.com/dcodeIO/protobuf.js/commit/aed134aa1cd7edd801de77c736cf5efe6fa61cb0) Updated non-bundled google types folder with missing descriptors and added wrappers to core<br />
2020
[:hash:](https://github.com/dcodeIO/protobuf.js/commit/0b0de2458a1ade1ccd4ceb789697be13290f856b) Replaced the ieee754 implementation for old browsers with a faster, use-case specific one + simple test case<br />
2121
[:hash:](https://github.com/dcodeIO/protobuf.js/commit/99ad9cc08721b834a197d4bbb67fa152d7ad79aa) Added .create to statically generated types and uppercase nested elements to reflection namespaces, see [#576](https://github.com/dcodeIO/protobuf.js/issues/576)<br />
2222
[:hash:](https://github.com/dcodeIO/protobuf.js/commit/99ad9cc08721b834a197d4bbb67fa152d7ad79aa) Also added Namespace#getEnum for completeness, see [#576](https://github.com/dcodeIO/protobuf.js/issues/576)<br />

dist/protobuf.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/protobuf.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/protobuf.min.js.gz

-610 Bytes
Binary file not shown.

dist/runtime/protobuf.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/runtime/protobuf.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/runtime/protobuf.min.js.gz

-100 Bytes
Binary file not shown.

gulpfile.js

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
var gulp = require("gulp"),
2-
gzip = require('gulp-gzip');
1+
var gulp = require("gulp");
32

43
var bundle = require("./scripts/bundle");
54

@@ -14,14 +13,18 @@ gulp.task("bundle-production" , bundle.bind(this, false, false));
1413
gulp.task("bundle-development-runtime", bundle.bind(this, true , true));
1514
gulp.task("bundle-production-runtime" , bundle.bind(this, false, true));
1615

17-
gulp.task("gzip-production", [ "bundle-production" ], function() {
18-
return gulp.src('./dist/protobuf.min.js')
19-
.pipe(gzip({ gzipOptions: { level: 9 } }))
20-
.pipe(gulp.dest('./dist'));
16+
gulp.task("gzip-production", [ "bundle-production" ], function(cb) {
17+
bundle.compress(
18+
"./dist/protobuf.min.js",
19+
"./dist/protobuf.min.js.gz",
20+
cb
21+
);
2122
});
2223

23-
gulp.task("gzip-production-runtime", [ "bundle-production-runtime" ], function() {
24-
return gulp.src('./dist/runtime/protobuf.min.js')
25-
.pipe(gzip({ gzipOptions: { level: 9 } }))
26-
.pipe(gulp.dest('./dist/runtime'));
24+
gulp.task("gzip-production-runtime", [ "bundle-production-runtime" ], function(cb) {
25+
bundle.compress(
26+
"./dist/runtime/protobuf.min.js",
27+
"./dist/runtime/protobuf.min.js.gz",
28+
cb
29+
);
2730
});

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
"jaguarjs-jsdoc": "dcodeIO/jaguarjs-jsdoc",
7777
"jsdoc": "^3.4.2",
7878
"minimist": "^1.2.0",
79+
"node-zopfli": "^2.0.2",
7980
"tap-spec": "^4.1.1",
8081
"tape": "^4.6.3",
8182
"typescript": "^2.1.4",

scripts/bundle.js

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
11
module.exports = bundle;
22

3-
var path = require('path');
3+
var path = require("path");
44

5-
var browserify = require('browserify');
5+
var browserify = require("browserify");
66

7-
var header = require('gulp-header');
8-
var gulpif = require('gulp-if');
9-
var sourcemaps = require('gulp-sourcemaps');
10-
var uglify = require('gulp-uglify');
11-
var gutil = require('gulp-util');
7+
var header = require("gulp-header");
8+
var gulpif = require("gulp-if");
9+
var sourcemaps = require("gulp-sourcemaps");
10+
var uglify = require("gulp-uglify");
11+
var gutil = require("gulp-util");
1212

13-
var buffer = require('vinyl-buffer');
14-
var vinylfs = require('vinyl-fs');
15-
var source = require('vinyl-source-stream');
13+
var buffer = require("vinyl-buffer");
14+
var vinylfs = require("vinyl-fs");
15+
var source = require("vinyl-source-stream");
1616

17-
var pkg = require(__dirname + '/../package.json');
17+
var pkg = require(__dirname + "/../package.json");
1818
var license = [
1919
"/*!",
2020
" * protobuf.js v${version} (c) 2016, Daniel Wirtz",
2121
" * Compiled ${date}",
22-
" * Licensed under the BSD-3-Clause license",
22+
" * Licensed under the BSD-3-Clause License",
2323
" * see: https://github.com/dcodeIO/protobuf.js for details",
2424
" */"
25-
].join('\n') + '\n';
25+
].join("\n") + "\n";
2626

2727
function bundle(compress, runtime) {
2828
var src = runtime
@@ -40,9 +40,9 @@ function bundle(compress, runtime) {
4040
.external("long")
4141
.exclude("process")
4242
.exclude("_process")
43-
.plugin(require('bundle-collapser/plugin'))
43+
.plugin(require("bundle-collapser/plugin"))
4444
.bundle()
45-
.pipe(source(compress ? 'protobuf.min.js' : 'protobuf.js'))
45+
.pipe(source(compress ? "protobuf.min.js" : "protobuf.js"))
4646
.pipe(buffer())
4747
.pipe(sourcemaps.init({ loadMaps: true }))
4848
.pipe(
@@ -53,11 +53,25 @@ function bundle(compress, runtime) {
5353
}))
5454
)
5555
.pipe(header(license, {
56-
date: (new Date()).toUTCString().replace('GMT', 'UTC'),
56+
date: (new Date()).toUTCString().replace("GMT", "UTC"),
5757
version: pkg.version
5858
}))
59-
.pipe(sourcemaps.write('.', { sourceRoot: '' }))
59+
.pipe(sourcemaps.write(".", { sourceRoot: "" }))
6060
.pipe(vinylfs.dest(dst))
6161
.on("log", gutil.log)
6262
.on("error", gutil.log);
6363
}
64+
65+
var fs = require("fs");
66+
var zopfli = require("node-zopfli");
67+
68+
bundle.compress = function compress(sourceFile, destinationFile, callback) {
69+
var src = fs.createReadStream(sourceFile);
70+
var dst = fs.createWriteStream(destinationFile);
71+
src.on("error", callback);
72+
dst.on("error", callback);
73+
dst.on("close", function() {
74+
callback(null);
75+
});
76+
src.pipe(zopfli.createGzip()).pipe(dst);
77+
};

0 commit comments

Comments
 (0)