@less-is-more/less-js 1.5.0-11 → 1.5.0-13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/cache.js +19 -12
package/package.json
CHANGED
package/src/cache.js
CHANGED
|
@@ -103,10 +103,14 @@ module.exports = class Cache {
|
|
|
103
103
|
} else {
|
|
104
104
|
console.log("Found cache" + (hasLocal ? " local" : ""), fullKey);
|
|
105
105
|
savedData = Cache._unzip(savedData);
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
106
|
+
if (savedData instanceof String) {
|
|
107
|
+
// 优先转成json
|
|
108
|
+
try {
|
|
109
|
+
return JSON.parse(savedData);
|
|
110
|
+
} catch (e) {
|
|
111
|
+
return savedData;
|
|
112
|
+
}
|
|
113
|
+
} else {
|
|
110
114
|
return savedData;
|
|
111
115
|
}
|
|
112
116
|
}
|
|
@@ -118,16 +122,19 @@ module.exports = class Cache {
|
|
|
118
122
|
}
|
|
119
123
|
|
|
120
124
|
static _unzip(content) {
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
125
|
+
if (typeof content === "string") {
|
|
126
|
+
let text = "";
|
|
127
|
+
const buffer = Buffer.from(content, "base64");
|
|
128
|
+
// 判断是否gzip
|
|
129
|
+
if (buffer.length > 2 && buffer[0] === 0x1f && buffer[1] === 0x8b) {
|
|
130
|
+
text = zlib.gunzipSync(buffer).toString();
|
|
131
|
+
} else {
|
|
132
|
+
text = content;
|
|
133
|
+
}
|
|
134
|
+
return text;
|
|
127
135
|
} else {
|
|
128
|
-
|
|
136
|
+
return content;
|
|
129
137
|
}
|
|
130
|
-
return text;
|
|
131
138
|
}
|
|
132
139
|
|
|
133
140
|
static _needZip(text, zip) {
|