Skip to content

Commit

Permalink
v1.0.2: Fixed decompression when multiple special entries exist (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicjansma committed Jul 11, 2018
1 parent 5100574 commit b0fa3ac
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 9 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# resourcetiming-compression.js

v1.0.1
v1.0.2

[http://nicj.net](http://nicj.net)

Expand Down Expand Up @@ -253,6 +253,8 @@ Or via ``gulp``:

## Version History

* v1.0.2 - 2018-07-06:
* Fixed decompression when multiple special entries exist
* v1.0.1 - 2018-04-13:
* Make hostname reversal configurable (#20)
* Add `naturalHeight` and `naturalWidth` to dimensionData (#20)
Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "resourcetiming-compression",
"version": "1.0.1",
"version": "1.0.2",
"homepage": "https://github.com/nicjansma/resourcetiming-compression.js",
"authors": [
"Nic Jansma <nic@nicj.net>",
Expand Down
2 changes: 1 addition & 1 deletion dist/resourcetiming-compression.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/resourcetiming-decompression.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "ResourceTiming compression and decompression",
"main": "./index.js",
"author": "Nic Jansma",
"version": "1.0.1",
"version": "1.0.2",
"repository": {
"type": "git",
"url": "http://github.com/nicjansma/resourcetiming-compression.js.git"
Expand Down
7 changes: 3 additions & 4 deletions src/resourcetiming-decompression.js
Original file line number Diff line number Diff line change
Expand Up @@ -570,8 +570,7 @@
var initiatorType = parseInt(data[0], 10);
data = data.length > 1 ? data.split(SPECIAL_DATA_PREFIX) : [];
var timings = data.length > 0 && data[0].length > 1 ? data[0].substring(1).split(",") : [];
var sizes = data.length > 1 ? data[1] : "";
var specialData = data.length > 1 ? data[1] : "";
var specialData = data.length > 1 ? data.slice(1) : [];

// convert all timings from base36
for (var i = 0; i < timings.length; i++) {
Expand Down Expand Up @@ -613,8 +612,8 @@
res.duration = res.responseEnd > 0 ? (res.responseEnd - res.startTime) : 0;

// decompress resource size data
if (sizes.length > 0) {
this.decompressSpecialData(specialData, res, st);
for (i = 0; i < specialData.length; i++) {
this.decompressSpecialData(specialData[i], res, st);
}

return res;
Expand Down
29 changes: 29 additions & 0 deletions test/test-resourcetiming-decompression.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,35 @@
// ResourceTimingDecompression
//
describe("ResourceTimingDecompression", function() {
//
// .decodeCompressedResource()
//
describe(".decodeCompressedResource()", function() {
it("should process more than one special datas", function() {
var entry = ResourceTimingDecompression.decodeCompressedResource(
"68y,95,7x,5s,5r,,3y,3y,1*1a,a,b*3100,:1",
"http://moc.oof",
["edge", ["cdn-cache", "HIT", "MISS"], "origin"]);

expect(entry.name).to.be("http://foo.com");
expect(entry.encodedBodySize).to.be(10);
expect(entry.transferSize).to.be(20);
expect(entry.decodedBodySize).to.be(21);
expect(entry.serverTiming).to.eql([
{
name: "edge",
description: "",
duration: 100
},
{
name: "cdn-cache",
description: "HIT",
duration: 0
}
]);
});
});

//
// .decodeCompressedResourceTimeStamp
//
Expand Down

0 comments on commit b0fa3ac

Please sign in to comment.