test-fs-replace.js 828 B

12345678910111213141516171819202122232425
  1. /* global URL */
  2. import * as zip from "../../index.js";
  3. const NEW_TEXT_CONTENT = "This is not the same text";
  4. const url = new URL("./../data/lorem.zip", import.meta.url).href;
  5. export { test };
  6. async function test() {
  7. zip.configure({ chunkSize: 128 });
  8. let zipFs = new zip.fs.FS();
  9. let directory = zipFs.addDirectory("import");
  10. await directory.importHttpContent(url, { preventHeadRequest: true });
  11. let firstEntry = directory.children[0];
  12. firstEntry.replaceText(NEW_TEXT_CONTENT);
  13. const blob = await zipFs.exportBlob();
  14. zipFs = new zip.fs.FS();
  15. await zipFs.importBlob(blob);
  16. directory = zipFs.getChildByName("import");
  17. firstEntry = directory.children[0];
  18. const text = await firstEntry.getText();
  19. zip.terminateWorkers();
  20. return text == NEW_TEXT_CONTENT && firstEntry.uncompressedSize == NEW_TEXT_CONTENT.length;
  21. }