Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

extract lastModified property from zip entries #461

Closed
bwkam opened this issue Nov 11, 2023 · 1 comment
Closed

extract lastModified property from zip entries #461

bwkam opened this issue Nov 11, 2023 · 1 comment

Comments

@bwkam
Copy link

bwkam commented Nov 11, 2023

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.

@gildas-lormeau
Copy link
Owner

The last modification date is accessible via the Entry#lastModDate property. See the example below.

<!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, BlobWriter } from "https://unpkg.com/@zip.js/zip.js/index.js";

zipFileInput.onchange = () => displayImages().catch(error => alert(error));

async function displayImages() {
  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

Repository owner locked and limited conversation to collaborators Nov 11, 2023
@gildas-lormeau gildas-lormeau converted this issue into discussion #462 Nov 11, 2023

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants