MCPcopy Create free account
hub / github.com/pacexy/flow / unpack

Function unpack

apps/reader/src/sync.ts:111–135  ·  view source on GitHub ↗
(file: File)

Source from the content-addressed store, hash-verified

109}
110
111export 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}

Callers 1

handleFilesFunction · 0.90

Calls 5

deserializeDataFunction · 0.85
putMethod · 0.80
parseMethod · 0.45
forEachMethod · 0.45
findMethod · 0.45

Tested by

no test coverage detected