(file: File)
| 109 | } |
| 110 | |
| 111 | export async function unpack(file: File) { |
| 112 | const zip = new JSZip() |
| 113 | await zip.loadAsync(file) |
| 114 | |
| 115 | const booksJSON = zip.file(DATA_FILENAME) |
| 116 | const coversJSON = zip.file('covers.json') |
| 117 | if (!booksJSON || !coversJSON) return |
| 118 | |
| 119 | const books = deserializeData(await booksJSON.async('text')) |
| 120 | |
| 121 | db?.books.bulkPut(books) |
| 122 | |
| 123 | const coversText = await coversJSON.async('text') |
| 124 | db?.covers.bulkPut(JSON.parse(coversText)) |
| 125 | |
| 126 | const folder = zip.folder('files') |
| 127 | folder?.forEach(async (_, f) => { |
| 128 | const book = books.find((b) => `files/${b.name}` === f.name) |
| 129 | if (!book) return |
| 130 | |
| 131 | const data = await f.async('blob') |
| 132 | const file = new File([data], book.name) |
| 133 | db?.files.put({ file, id: book.id }) |
| 134 | }) |
| 135 | } |
no test coverage detected