@tim-code/my-util 0.0.1 → 0.0.2
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 +4 -1
- package/src/fs.js +3 -0
- package/src/fs.test.js +3 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tim-code/my-util",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.2",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"author": "",
|
|
@@ -23,5 +23,8 @@
|
|
|
23
23
|
},
|
|
24
24
|
"jest": {
|
|
25
25
|
"transform": {}
|
|
26
|
+
},
|
|
27
|
+
"publishConfig": {
|
|
28
|
+
"access": "public"
|
|
26
29
|
}
|
|
27
30
|
}
|
package/src/fs.js
CHANGED
|
@@ -24,6 +24,9 @@ export async function getJSON(path) {
|
|
|
24
24
|
* @returns {Object|Array}
|
|
25
25
|
*/
|
|
26
26
|
export async function getCompressedJSON(path) {
|
|
27
|
+
if (!path.endsWith(".gz")) {
|
|
28
|
+
throw new Error("path does not suggest a compressed file")
|
|
29
|
+
}
|
|
27
30
|
const buffer = await readFile(path)
|
|
28
31
|
const uncompressed = await gunzip(buffer)
|
|
29
32
|
return JSON.parse(uncompressed.toString())
|
package/src/fs.test.js
CHANGED
|
@@ -42,6 +42,9 @@ describe("getCompressedJSON", () => {
|
|
|
42
42
|
expect(readFileMock).toHaveBeenCalledWith("bar.gz")
|
|
43
43
|
expect(gunzipMock).toHaveBeenCalled()
|
|
44
44
|
})
|
|
45
|
+
it("throws for bad filename", async () => {
|
|
46
|
+
await expect(getCompressedJSON("bar")).rejects.toThrow(/a compressed file/u)
|
|
47
|
+
})
|
|
45
48
|
})
|
|
46
49
|
|
|
47
50
|
describe("pathExists", () => {
|