extract lastModified
property from zip entries
#462
-
Hi, I recently discovered this library and it seems pretty good. I was just wondering if I can access the lastModified property from files in the zip because I need that info in my app. Thanks. |
Beta Was this translation helpful? Give feedback.
Answered by
gildas-lormeau
Nov 11, 2023
Replies: 1 comment 9 replies
-
The last modification date is accessible via the <!doctype html>
<html>
<head>
<title>Display last modification dates of entries in a zip file</title>
<style>
table {
margin-block-start: 8px;
border-collapse: collapse;
}
td {
border: 1px dotted grey;
padding: 4px;
}
</style>
</head>
<body>
<form>
<input type=file id=zipFileInput>
</form>
<div id=result>
</div>
<script type=module>
import { ZipReader, BlobReader } from "https://unpkg.com/@zip.js/zip.js/index.js";
zipFileInput.onchange = () => display().catch(error => alert(error));
async function display() {
const zipReader = new ZipReader(new BlobReader(zipFileInput.files[0]));
const entries = await zipReader.getEntries();
const tableElement = document.createElement("table");
entries.forEach(entry => {
const rowElement = document.createElement("tr");
const filenameElement = document.createElement("td");
const lastModDateElement = document.createElement("td");
filenameElement.textContent = entry.filename;
lastModDateElement.textContent = entry.lastModDate;
rowElement.appendChild(filenameElement);
rowElement.appendChild(lastModDateElement);
tableElement.appendChild(rowElement);
});
result.innerHTML = "";
result.appendChild(tableElement);
}
</script>
</body>
</html> Run it on plnkr: https://plnkr.co/edit/X1MwY0hbk2aCxOcM |
Beta Was this translation helpful? Give feedback.
9 replies
Answer selected by
bwkam
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The last modification date is accessible via the
Entry#lastModDate
property. See the example below.