You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@daffodil.apache.org by GitBox <gi...@apache.org> on 2021/01/27 21:30:44 UTC

[GitHub] [incubator-daffodil] mbeckerle commented on a change in pull request #480: WIP: First cut at a Zip layer transform

mbeckerle commented on a change in pull request #480:
URL: https://github.com/apache/incubator-daffodil/pull/480#discussion_r565647658



##########
File path: daffodil-runtime1/src/main/scala/org/apache/daffodil/layers/ZipTransformer.scala
##########
@@ -0,0 +1,335 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.daffodil.layers
+
+import org.apache.commons.compress.archivers.zip.ZipArchiveEntry
+import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream
+import org.apache.commons.compress.archivers.zip.ZipFile
+import org.apache.commons.compress.utils.SeekableInMemoryByteChannel
+import org.apache.commons.io.IOUtils
+import org.apache.daffodil.schema.annotation.props.gen.LayerLengthKind
+import org.apache.daffodil.schema.annotation.props.gen.LayerLengthUnits
+import org.apache.daffodil.util.Maybe
+import org.apache.daffodil.processors.LayerLengthInBytesEv
+import org.apache.daffodil.processors.LayerBoundaryMarkEv
+import org.apache.daffodil.processors.LayerCharsetEv
+import org.apache.daffodil.processors.parsers.PState
+import org.apache.daffodil.processors.unparsers.UState
+import org.apache.daffodil.dsom.DPathCompileInfo
+import org.apache.daffodil.exceptions.Assert
+import org.apache.daffodil.io.ExplicitLengthLimitingStream
+
+import java.io.ByteArrayInputStream
+import java.io.ByteArrayOutputStream
+import java.io.InputStream
+import java.io.OutputStream
+import java.io.SequenceInputStream
+import java.nio.charset.StandardCharsets
+import scala.Array.emptyByteArray
+import scala.collection.JavaConverters._
+
+/*
+ * Zip files require seeking to the end of the file. Hence, we need to have an explicit
+ * length for a zip layer to work from.
+ *
+ * When writing out zip file contents, to get the length, one must take the
+ * dfdl:contentLength of an enclosing element that surrounds the entire layer.
+ *
+ * All of this forces buffering. So there's no point in worrying about
+ * somehow avoiding buffering inside the implementation.
+ * That can simplify many things. There's no point, for example, in trying
+ * to not read and buffer all the entries.

Review comment:
       I think we need to be clear on the goals here, and maybe this feature should be renamed to narrow it, so that it is not seen as something more general. This is not zip-file support for Daffodil. 
   
   The specific use case is of messages which have a binary envelope, the payload is the bytes of a zip file. If the zip file contains a file with extension ".xml" that's just a string (of XML). However, if the zip contains ".bin" files, those contain data in a specific binary format, that can be parsed/unparsed using DFDL. 
   
   I wanted to see if Daffodil layer transforms could use an underlying library to cope with zip. It seems they can, so long as the data is small enough to fit within the max size Daffodil can handle. 
   




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org