Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "do-not-zip",
"version": "1.0.0",
"version": "1.0.1",
"description": "Do not zip. Just store.",
"keywords": [
"browser",
Expand Down
2 changes: 1 addition & 1 deletion src/toArray.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const int = (n, length) => {
return out;
};

const toBytes = data => typeof data === 'string' ? [...data].map(char => char.charCodeAt(0)) : data;
const toBytes = data => typeof data === 'string' ? new TextEncoder().encode(data) : data;

export default files => {
let fileData = [];
Expand Down
8 changes: 4 additions & 4 deletions test/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ module.exports = {
},
jzipToEntries(jzip) {
const ary = []
jzip.forEach((path, file) => ary.push({ path, file }))
return ary
jzip.forEach((path, file) => ary.push(file.async("string").then((str) => ({ path, str }))))
return Promise.all(ary)
},
entriesToObject(entries) {
return entries.reduce((acc, { path, file }) => {
acc[path] = file
return entries.reduce((acc, { path, str }) => {
acc[path] = str
return acc
}, Object.create(null))
},
Expand Down
29 changes: 20 additions & 9 deletions test/test.everywhere.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,28 @@ const doNotZip = require(`../`)
const { loadJzip, jzipToEntries, entriesToObject } = require(`./helper.js`)

test(`Creates a zip file that jszip can read`, async t => {
const outputBlob = doNotZip.toAuto([
{ path: `path/to/file1.txt`, data: `Hello` },
{ path: `another/file2.txt`, data: `World` },
])
const entries = jzipToEntries(await loadJzip(outputBlob))
const data = [
{ path: `path/to/file1.txt`, data: `Hello` },
{ path: `another/file2.txt`, data: `World` },
{ path: `cyrillic_text.txt`, data: `абвгде` },
{ path: `surrogateChar.txt`, data: `\uD800\uDC00` },
];
const outputBlob = doNotZip.toAuto(data)
const entries = await jzipToEntries(await loadJzip(outputBlob))

const expectedPaths = [ `path/to/file1.txt`, `another/file2.txt` ]

t.equal(entries.length, expectedPaths.length)
t.equal(entries.length, data.length)

const jzipMap = entriesToObject(entries)

expectedPaths.forEach(expectedPath => t.ok(expectedPath in jzipMap))
t.test(`All the files presented in the archive`, t => {
data.forEach(({ path, data }) => {
t.ok(path in jzipMap);
})
})

t.test(`All the contents are the same`, t => {
data.forEach(({ path, data }) => {
t.equal(data, jzipMap[path]);
})
})
})