summaryrefslogtreecommitdiff
path: root/examples/scala-js/javalib-ex/src/main/scala/java/util/zip/ZipInputStream.scala
diff options
context:
space:
mode:
Diffstat (limited to 'examples/scala-js/javalib-ex/src/main/scala/java/util/zip/ZipInputStream.scala')
-rw-r--r--examples/scala-js/javalib-ex/src/main/scala/java/util/zip/ZipInputStream.scala87
1 files changed, 0 insertions, 87 deletions
diff --git a/examples/scala-js/javalib-ex/src/main/scala/java/util/zip/ZipInputStream.scala b/examples/scala-js/javalib-ex/src/main/scala/java/util/zip/ZipInputStream.scala
deleted file mode 100644
index 082f6fc..0000000
--- a/examples/scala-js/javalib-ex/src/main/scala/java/util/zip/ZipInputStream.scala
+++ /dev/null
@@ -1,87 +0,0 @@
-package java.util.zip
-
-import java.io._
-
-import scala.scalajs.js
-import scala.scalajs.js.typedarray._
-
-class ZipInputStream(in: InputStream) extends InflaterInputStream(in) {
-
- // Not implemented
- // - All static constant fields (zip internals)
- // - protected def createZipEntry(name: String): ZipEntry
-
- private[this] val entryIter = {
- import js.Dynamic.{global => g}
-
- val data = in match {
- case in: ArrayBufferInputStream =>
- // Simulate reading all the data
- while (in.skip(in.available()) > 0) {}
- new Uint8Array(in.buffer, in.offset, in.length)
- case _ =>
- val arr = new js.Array[Int]
- var x = in.read()
- while (x != -1) {
- arr.push(x)
- x = in.read()
- }
- new Uint8Array(arr)
- }
-
- val zip = js.Dynamic.newInstance(g.JSZip)(data)
- val entries = zip.files.asInstanceOf[js.Dictionary[js.Dynamic]]
-
- entries.iterator
- }
-
- private[this] var inner: ArrayBufferInputStream = null
-
- override def close(): Unit = {
- closeEntry()
- super.close()
- }
-
- override def available(): Int = {
- if (inner == null || inner.available() <= 0) 0
- else 1
- }
-
- def closeEntry(): Unit = {
- if (inner != null)
- inner.close()
- inner = null
- }
-
- def getNextEntry(): ZipEntry = {
- closeEntry()
- if (entryIter.hasNext) {
- val (name, jsEntry) = entryIter.next()
- val res = new ZipEntry(name)
- res.setTime(jsEntry.date.asInstanceOf[js.Date].getTime().toLong)
- res.setComment(jsEntry.comment.asInstanceOf[String])
-
- inner = new ArrayBufferInputStream(
- jsEntry.asArrayBuffer().asInstanceOf[ArrayBuffer])
-
- res
- } else null
- }
-
- override def read(): Int = {
- if (inner == null) -1
- else inner.read()
- }
-
- override def read(buf: Array[Byte], off: Int, len: Int): Int = {
- if (len == 0) 0
- else if (inner == null) -1
- else inner.read(buf, off, len)
- }
-
- override def skip(n: Long): Long = {
- if (inner == null) 0
- else inner.skip(n)
- }
-
-}