author | wenzelm |
Sun, 26 Mar 2023 19:31:05 +0200 | |
changeset 77716 | 3f4163b83d4f |
parent 77714 | be0b9396604e |
child 77717 | 6a2daddc238c |
permissions | -rw-r--r-- |
54439 | 1 |
/* Title: Pure/General/bytes.scala |
2 |
Author: Makarius |
|
3 |
||
4 |
Immutable byte vectors versus UTF8 strings. |
|
5 |
*/ |
|
6 |
||
7 |
package isabelle |
|
8 |
||
9 |
||
76351
2cee31cd92f0
generic support for XZ and Zstd compression in Isabelle/Scala;
wenzelm
parents:
76350
diff
changeset
|
10 |
import java.io.{ByteArrayInputStream, ByteArrayOutputStream, FileInputStream, FileOutputStream, InputStream, OutputStream, File as JFile} |
65070 | 11 |
import java.net.URL |
77711
25fd62cba347
clarified signature: more general operation Bytes.read_slice;
wenzelm
parents:
76361
diff
changeset
|
12 |
import java.nio.ByteBuffer |
25fd62cba347
clarified signature: more general operation Bytes.read_slice;
wenzelm
parents:
76361
diff
changeset
|
13 |
import java.nio.channels.FileChannel |
25fd62cba347
clarified signature: more general operation Bytes.read_slice;
wenzelm
parents:
76361
diff
changeset
|
14 |
import java.nio.file.StandardOpenOption |
77712
dd4bb80dbc3a
tuned performance: much faster low-level operation;
wenzelm
parents:
77711
diff
changeset
|
15 |
import java.util.Arrays |
76353 | 16 |
import org.tukaani.xz |
17 |
import com.github.luben.zstd |
|
54440 | 18 |
|
19 |
||
75393 | 20 |
object Bytes { |
54439 | 21 |
val empty: Bytes = new Bytes(Array[Byte](), 0, 0) |
22 |
||
75393 | 23 |
def apply(s: CharSequence): Bytes = { |
54439 | 24 |
val str = s.toString |
25 |
if (str.isEmpty) empty |
|
26 |
else { |
|
62527 | 27 |
val b = UTF8.bytes(str) |
54442
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents:
54440
diff
changeset
|
28 |
new Bytes(b, 0, b.length) |
54439 | 29 |
} |
30 |
} |
|
54440 | 31 |
|
63779 | 32 |
def apply(a: Array[Byte]): Bytes = apply(a, 0, a.length) |
33 |
||
54442
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents:
54440
diff
changeset
|
34 |
def apply(a: Array[Byte], offset: Int, length: Int): Bytes = |
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents:
54440
diff
changeset
|
35 |
if (length == 0) empty |
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents:
54440
diff
changeset
|
36 |
else { |
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents:
54440
diff
changeset
|
37 |
val b = new Array[Byte](length) |
55618 | 38 |
System.arraycopy(a, offset, b, 0, length) |
54442
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents:
54440
diff
changeset
|
39 |
new Bytes(b, 0, b.length) |
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents:
54440
diff
changeset
|
40 |
} |
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents:
54440
diff
changeset
|
41 |
|
69454 | 42 |
val newline: Bytes = apply("\n") |
54440 | 43 |
|
73576 | 44 |
|
45 |
/* base64 */ |
|
46 |
||
75587 | 47 |
def decode_base64(s: String): Bytes = { |
75620 | 48 |
val a = Base64.decode(s) |
68108 | 49 |
new Bytes(a, 0, a.length) |
50 |
} |
|
51 |
||
75579 | 52 |
|
54440 | 53 |
/* read */ |
54 |
||
64005
f6e965cf1617
clarified magic values (see also java/io/BufferedInputStream.java);
wenzelm
parents:
64004
diff
changeset
|
55 |
def read_stream(stream: InputStream, limit: Int = Integer.MAX_VALUE, hint: Int = 1024): Bytes = |
64004 | 56 |
if (limit == 0) empty |
57 |
else { |
|
73414 | 58 |
val out_size = (if (limit == Integer.MAX_VALUE) hint else limit) max 1024 |
59 |
val out = new ByteArrayOutputStream(out_size) |
|
64005
f6e965cf1617
clarified magic values (see also java/io/BufferedInputStream.java);
wenzelm
parents:
64004
diff
changeset
|
60 |
val buf = new Array[Byte](8192) |
64004 | 61 |
var m = 0 |
54440 | 62 |
|
75709 | 63 |
while ({ |
73554 | 64 |
m = stream.read(buf, 0, buf.length min (limit - out.size)) |
64004 | 65 |
if (m != -1) out.write(buf, 0, m) |
75709 | 66 |
m != -1 && limit > out.size |
67 |
}) () |
|
64004 | 68 |
|
69 |
new Bytes(out.toByteArray, 0, out.size) |
|
54440 | 70 |
} |
64001
7ecb22be8f03
more general read_stream: return actual byte count;
wenzelm
parents:
63779
diff
changeset
|
71 |
|
75393 | 72 |
def read(file: JFile): Bytes = { |
71152
f2d848a596d1
more robust: file length can be invalid in odd situations;
wenzelm
parents:
71151
diff
changeset
|
73 |
val length = file.length |
f2d848a596d1
more robust: file length can be invalid in odd situations;
wenzelm
parents:
71151
diff
changeset
|
74 |
val limit = if (length < 0 || length > Integer.MAX_VALUE) Integer.MAX_VALUE else length.toInt |
f2d848a596d1
more robust: file length can be invalid in odd situations;
wenzelm
parents:
71151
diff
changeset
|
75 |
using(new FileInputStream(file))(read_stream(_, limit = limit)) |
f2d848a596d1
more robust: file length can be invalid in odd situations;
wenzelm
parents:
71151
diff
changeset
|
76 |
} |
64229 | 77 |
|
78 |
def read(path: Path): Bytes = read(path.file) |
|
79 |
||
65070 | 80 |
def read(url: URL): Bytes = using(url.openStream)(read_stream(_)) |
81 |
||
77711
25fd62cba347
clarified signature: more general operation Bytes.read_slice;
wenzelm
parents:
76361
diff
changeset
|
82 |
def read_slice(path: Path, offset: Long = 0L, limit: Long = Long.MaxValue): Bytes = { |
25fd62cba347
clarified signature: more general operation Bytes.read_slice;
wenzelm
parents:
76361
diff
changeset
|
83 |
val start = offset.max(0L) |
25fd62cba347
clarified signature: more general operation Bytes.read_slice;
wenzelm
parents:
76361
diff
changeset
|
84 |
val len = (path.file.length - start).max(0L).min(limit) |
25fd62cba347
clarified signature: more general operation Bytes.read_slice;
wenzelm
parents:
76361
diff
changeset
|
85 |
if (len > Integer.MAX_VALUE) error("Cannot read large file slice: " + Space.bytes(len).print) |
25fd62cba347
clarified signature: more general operation Bytes.read_slice;
wenzelm
parents:
76361
diff
changeset
|
86 |
else if (len == 0L) empty |
25fd62cba347
clarified signature: more general operation Bytes.read_slice;
wenzelm
parents:
76361
diff
changeset
|
87 |
else { |
25fd62cba347
clarified signature: more general operation Bytes.read_slice;
wenzelm
parents:
76361
diff
changeset
|
88 |
using(FileChannel.open(path.java_path, StandardOpenOption.READ)) { file => |
25fd62cba347
clarified signature: more general operation Bytes.read_slice;
wenzelm
parents:
76361
diff
changeset
|
89 |
file.position(start) |
25fd62cba347
clarified signature: more general operation Bytes.read_slice;
wenzelm
parents:
76361
diff
changeset
|
90 |
val n = len.toInt |
25fd62cba347
clarified signature: more general operation Bytes.read_slice;
wenzelm
parents:
76361
diff
changeset
|
91 |
val buf = ByteBuffer.allocate(n) |
25fd62cba347
clarified signature: more general operation Bytes.read_slice;
wenzelm
parents:
76361
diff
changeset
|
92 |
var i = 0 |
25fd62cba347
clarified signature: more general operation Bytes.read_slice;
wenzelm
parents:
76361
diff
changeset
|
93 |
var m = 0 |
25fd62cba347
clarified signature: more general operation Bytes.read_slice;
wenzelm
parents:
76361
diff
changeset
|
94 |
while ({ |
25fd62cba347
clarified signature: more general operation Bytes.read_slice;
wenzelm
parents:
76361
diff
changeset
|
95 |
m = file.read(buf) |
25fd62cba347
clarified signature: more general operation Bytes.read_slice;
wenzelm
parents:
76361
diff
changeset
|
96 |
if (m != -1) i += m |
25fd62cba347
clarified signature: more general operation Bytes.read_slice;
wenzelm
parents:
76361
diff
changeset
|
97 |
m != -1 && n > i |
25fd62cba347
clarified signature: more general operation Bytes.read_slice;
wenzelm
parents:
76361
diff
changeset
|
98 |
}) () |
25fd62cba347
clarified signature: more general operation Bytes.read_slice;
wenzelm
parents:
76361
diff
changeset
|
99 |
new Bytes(buf.array, 0, i) |
25fd62cba347
clarified signature: more general operation Bytes.read_slice;
wenzelm
parents:
76361
diff
changeset
|
100 |
} |
25fd62cba347
clarified signature: more general operation Bytes.read_slice;
wenzelm
parents:
76361
diff
changeset
|
101 |
} |
25fd62cba347
clarified signature: more general operation Bytes.read_slice;
wenzelm
parents:
76361
diff
changeset
|
102 |
} |
25fd62cba347
clarified signature: more general operation Bytes.read_slice;
wenzelm
parents:
76361
diff
changeset
|
103 |
|
64229 | 104 |
|
105 |
/* write */ |
|
106 |
||
69393
ed0824ef337e
static type for Library.using: avoid Java 11 warnings on "Illegal reflective access";
wenzelm
parents:
69365
diff
changeset
|
107 |
def write(file: JFile, bytes: Bytes): Unit = |
ed0824ef337e
static type for Library.using: avoid Java 11 warnings on "Illegal reflective access";
wenzelm
parents:
69365
diff
changeset
|
108 |
using(new FileOutputStream(file))(bytes.write_stream(_)) |
64229 | 109 |
|
110 |
def write(path: Path, bytes: Bytes): Unit = write(path.file, bytes) |
|
54439 | 111 |
} |
112 |
||
113 |
final class Bytes private( |
|
114 |
protected val bytes: Array[Byte], |
|
115 |
protected val offset: Int, |
|
75393 | 116 |
val length: Int) extends CharSequence { |
54439 | 117 |
/* equality */ |
118 |
||
75393 | 119 |
override def equals(that: Any): Boolean = { |
54440 | 120 |
that match { |
121 |
case other: Bytes => |
|
77712
dd4bb80dbc3a
tuned performance: much faster low-level operation;
wenzelm
parents:
77711
diff
changeset
|
122 |
this.eq(other) || |
dd4bb80dbc3a
tuned performance: much faster low-level operation;
wenzelm
parents:
77711
diff
changeset
|
123 |
Arrays.equals(bytes, offset, offset + length, |
dd4bb80dbc3a
tuned performance: much faster low-level operation;
wenzelm
parents:
77711
diff
changeset
|
124 |
other.bytes, other.offset, other.offset + other.length) |
54440 | 125 |
case _ => false |
126 |
} |
|
127 |
} |
|
128 |
||
75393 | 129 |
private lazy val hash: Int = { |
54439 | 130 |
var h = 0 |
131 |
for (i <- offset until offset + length) { |
|
132 |
val b = bytes(i).asInstanceOf[Int] & 0xFF |
|
133 |
h = 31 * h + b |
|
134 |
} |
|
135 |
h |
|
136 |
} |
|
137 |
||
138 |
override def hashCode(): Int = hash |
|
139 |
||
140 |
||
141 |
/* content */ |
|
142 |
||
54512 | 143 |
lazy val sha1_digest: SHA1.Digest = SHA1.digest(bytes) |
54440 | 144 |
|
69448 | 145 |
def is_empty: Boolean = length == 0 |
146 |
||
147 |
def iterator: Iterator[Byte] = |
|
148 |
for (i <- (offset until (offset + length)).iterator) |
|
149 |
yield bytes(i) |
|
150 |
||
75393 | 151 |
def array: Array[Byte] = { |
69365
c5b3860d29ef
avoid loading of font file, to eliminate "Illegal reflective access by com.lowagie.text.pdf.MappedRandomAccessFile$1 (iText-2.1.5.jar) to method java.nio.DirectByteBuffer.cleaner()" -- due to com.lowagie.text.pdf.TrueTypeFont.process() / RandomAccessFileOrArray;
wenzelm
parents:
68167
diff
changeset
|
152 |
val a = new Array[Byte](length) |
c5b3860d29ef
avoid loading of font file, to eliminate "Illegal reflective access by com.lowagie.text.pdf.MappedRandomAccessFile$1 (iText-2.1.5.jar) to method java.nio.DirectByteBuffer.cleaner()" -- due to com.lowagie.text.pdf.TrueTypeFont.process() / RandomAccessFileOrArray;
wenzelm
parents:
68167
diff
changeset
|
153 |
System.arraycopy(bytes, offset, a, 0, length) |
c5b3860d29ef
avoid loading of font file, to eliminate "Illegal reflective access by com.lowagie.text.pdf.MappedRandomAccessFile$1 (iText-2.1.5.jar) to method java.nio.DirectByteBuffer.cleaner()" -- due to com.lowagie.text.pdf.TrueTypeFont.process() / RandomAccessFileOrArray;
wenzelm
parents:
68167
diff
changeset
|
154 |
a |
c5b3860d29ef
avoid loading of font file, to eliminate "Illegal reflective access by com.lowagie.text.pdf.MappedRandomAccessFile$1 (iText-2.1.5.jar) to method java.nio.DirectByteBuffer.cleaner()" -- due to com.lowagie.text.pdf.TrueTypeFont.process() / RandomAccessFileOrArray;
wenzelm
parents:
68167
diff
changeset
|
155 |
} |
c5b3860d29ef
avoid loading of font file, to eliminate "Illegal reflective access by com.lowagie.text.pdf.MappedRandomAccessFile$1 (iText-2.1.5.jar) to method java.nio.DirectByteBuffer.cleaner()" -- due to com.lowagie.text.pdf.TrueTypeFont.process() / RandomAccessFileOrArray;
wenzelm
parents:
68167
diff
changeset
|
156 |
|
73561
c83152933579
clarified signature: Bytes extends CharSequence already (see d201996f72a8);
wenzelm
parents:
73559
diff
changeset
|
157 |
def text: String = UTF8.decode_permissive(this) |
65279
fa62e095d8f1
clarified signature (again, see also 3ed43cfc8b14);
wenzelm
parents:
65070
diff
changeset
|
158 |
|
76236 | 159 |
def wellformed_text: Option[String] = { |
160 |
val s = text |
|
161 |
if (this == Bytes(s)) Some(s) else None |
|
162 |
} |
|
163 |
||
75587 | 164 |
def encode_base64: String = { |
68094 | 165 |
val b = |
166 |
if (offset == 0 && length == bytes.length) bytes |
|
167 |
else Bytes(bytes, offset, length).bytes |
|
75620 | 168 |
Base64.encode(b) |
68094 | 169 |
} |
170 |
||
76236 | 171 |
def maybe_encode_base64: (Boolean, String) = |
172 |
wellformed_text match { |
|
173 |
case Some(s) => (false, s) |
|
174 |
case None => (true, encode_base64) |
|
175 |
} |
|
68106 | 176 |
|
77716 | 177 |
override def toString: String = |
178 |
if (is_empty) "Bytes.empty" else "Bytes(" + Space.bytes(length).print + ")" |
|
54439 | 179 |
|
72885 | 180 |
def proper: Option[Bytes] = if (is_empty) None else Some(this) |
181 |
def proper_text: Option[String] = if (is_empty) None else Some(text) |
|
65630 | 182 |
|
54439 | 183 |
def +(other: Bytes): Bytes = |
72885 | 184 |
if (other.is_empty) this |
185 |
else if (is_empty) other |
|
54439 | 186 |
else { |
187 |
val new_bytes = new Array[Byte](length + other.length) |
|
55618 | 188 |
System.arraycopy(bytes, offset, new_bytes, 0, length) |
189 |
System.arraycopy(other.bytes, other.offset, new_bytes, length, other.length) |
|
54439 | 190 |
new Bytes(new_bytes, 0, new_bytes.length) |
191 |
} |
|
54440 | 192 |
|
193 |
||
60833 | 194 |
/* CharSequence operations */ |
195 |
||
196 |
def charAt(i: Int): Char = |
|
197 |
if (0 <= i && i < length) (bytes(offset + i).asInstanceOf[Int] & 0xFF).asInstanceOf[Char] |
|
198 |
else throw new IndexOutOfBoundsException |
|
199 |
||
75393 | 200 |
def subSequence(i: Int, j: Int): Bytes = { |
60833 | 201 |
if (0 <= i && i <= j && j <= length) new Bytes(bytes, offset + i, j - i) |
202 |
else throw new IndexOutOfBoundsException |
|
203 |
} |
|
204 |
||
69448 | 205 |
def trim_line: Bytes = |
77714 | 206 |
if (length >= 2 && charAt(length - 2) == 13 && charAt(length - 1) == 10) { |
69448 | 207 |
subSequence(0, length - 2) |
77714 | 208 |
} |
209 |
else if (length >= 1 && (charAt(length - 1) == 13 || charAt(length - 1) == 10)) { |
|
69448 | 210 |
subSequence(0, length - 1) |
77714 | 211 |
} |
69448 | 212 |
else this |
213 |
||
60833 | 214 |
|
64004 | 215 |
/* streams */ |
216 |
||
217 |
def stream(): ByteArrayInputStream = new ByteArrayInputStream(bytes, offset, length) |
|
218 |
||
219 |
def write_stream(stream: OutputStream): Unit = stream.write(bytes, offset, length) |
|
220 |
||
221 |
||
76351
2cee31cd92f0
generic support for XZ and Zstd compression in Isabelle/Scala;
wenzelm
parents:
76350
diff
changeset
|
222 |
/* XZ / Zstd data compression */ |
2cee31cd92f0
generic support for XZ and Zstd compression in Isabelle/Scala;
wenzelm
parents:
76350
diff
changeset
|
223 |
|
76358 | 224 |
def detect_xz: Boolean = |
76351
2cee31cd92f0
generic support for XZ and Zstd compression in Isabelle/Scala;
wenzelm
parents:
76350
diff
changeset
|
225 |
length >= 6 && |
2cee31cd92f0
generic support for XZ and Zstd compression in Isabelle/Scala;
wenzelm
parents:
76350
diff
changeset
|
226 |
bytes(offset) == 0xFD.toByte && |
2cee31cd92f0
generic support for XZ and Zstd compression in Isabelle/Scala;
wenzelm
parents:
76350
diff
changeset
|
227 |
bytes(offset + 1) == 0x37.toByte && |
2cee31cd92f0
generic support for XZ and Zstd compression in Isabelle/Scala;
wenzelm
parents:
76350
diff
changeset
|
228 |
bytes(offset + 2) == 0x7A.toByte && |
2cee31cd92f0
generic support for XZ and Zstd compression in Isabelle/Scala;
wenzelm
parents:
76350
diff
changeset
|
229 |
bytes(offset + 3) == 0x58.toByte && |
2cee31cd92f0
generic support for XZ and Zstd compression in Isabelle/Scala;
wenzelm
parents:
76350
diff
changeset
|
230 |
bytes(offset + 4) == 0x5A.toByte && |
2cee31cd92f0
generic support for XZ and Zstd compression in Isabelle/Scala;
wenzelm
parents:
76350
diff
changeset
|
231 |
bytes(offset + 5) == 0x00.toByte |
2cee31cd92f0
generic support for XZ and Zstd compression in Isabelle/Scala;
wenzelm
parents:
76350
diff
changeset
|
232 |
|
76358 | 233 |
def detect_zstd: Boolean = |
76351
2cee31cd92f0
generic support for XZ and Zstd compression in Isabelle/Scala;
wenzelm
parents:
76350
diff
changeset
|
234 |
length >= 4 && |
2cee31cd92f0
generic support for XZ and Zstd compression in Isabelle/Scala;
wenzelm
parents:
76350
diff
changeset
|
235 |
bytes(offset) == 0x28.toByte && |
2cee31cd92f0
generic support for XZ and Zstd compression in Isabelle/Scala;
wenzelm
parents:
76350
diff
changeset
|
236 |
bytes(offset + 1) == 0xB5.toByte && |
2cee31cd92f0
generic support for XZ and Zstd compression in Isabelle/Scala;
wenzelm
parents:
76350
diff
changeset
|
237 |
bytes(offset + 2) == 0x2F.toByte && |
2cee31cd92f0
generic support for XZ and Zstd compression in Isabelle/Scala;
wenzelm
parents:
76350
diff
changeset
|
238 |
bytes(offset + 3) == 0xFD.toByte |
2cee31cd92f0
generic support for XZ and Zstd compression in Isabelle/Scala;
wenzelm
parents:
76350
diff
changeset
|
239 |
|
76358 | 240 |
def uncompress_xz(cache: Compress.Cache = Compress.Cache.none): Bytes = |
241 |
using(new xz.XZInputStream(stream(), cache.for_xz))(Bytes.read_stream(_, hint = length)) |
|
242 |
||
243 |
def uncompress_zstd(cache: Compress.Cache = Compress.Cache.none): Bytes = { |
|
244 |
Zstd.init() |
|
245 |
val n = zstd.Zstd.decompressedSize(bytes, offset, length) |
|
246 |
if (n > 0 && n < Integer.MAX_VALUE) { |
|
247 |
Bytes(zstd.Zstd.decompress(array, n.toInt)) |
|
248 |
} |
|
249 |
else { |
|
250 |
using(new zstd.ZstdInputStream(stream(), cache.for_zstd))(Bytes.read_stream(_, hint = length)) |
|
251 |
} |
|
252 |
} |
|
54440 | 253 |
|
76351
2cee31cd92f0
generic support for XZ and Zstd compression in Isabelle/Scala;
wenzelm
parents:
76350
diff
changeset
|
254 |
def uncompress(cache: Compress.Cache = Compress.Cache.none): Bytes = |
76358 | 255 |
if (detect_xz) uncompress_xz(cache = cache) |
256 |
else if (detect_zstd) uncompress_zstd(cache = cache) |
|
257 |
else error("Cannot detect compression scheme") |
|
64004 | 258 |
|
76351
2cee31cd92f0
generic support for XZ and Zstd compression in Isabelle/Scala;
wenzelm
parents:
76350
diff
changeset
|
259 |
def compress( |
2cee31cd92f0
generic support for XZ and Zstd compression in Isabelle/Scala;
wenzelm
parents:
76350
diff
changeset
|
260 |
options: Compress.Options = Compress.Options(), |
2cee31cd92f0
generic support for XZ and Zstd compression in Isabelle/Scala;
wenzelm
parents:
76350
diff
changeset
|
261 |
cache: Compress.Cache = Compress.Cache.none |
2cee31cd92f0
generic support for XZ and Zstd compression in Isabelle/Scala;
wenzelm
parents:
76350
diff
changeset
|
262 |
): Bytes = { |
76358 | 263 |
options match { |
264 |
case options_xz: Compress.Options_XZ => |
|
265 |
val result = new ByteArrayOutputStream(length) |
|
266 |
using(new xz.XZOutputStream(result, options_xz.make, cache.for_xz))(write_stream) |
|
267 |
new Bytes(result.toByteArray, 0, result.size) |
|
268 |
case options_zstd: Compress.Options_Zstd => |
|
269 |
Zstd.init() |
|
76361
3b9f36ef7365
tuned: avoid redundant copy of potentially large array;
wenzelm
parents:
76358
diff
changeset
|
270 |
Bytes(zstd.Zstd.compress(if (offset == 0) bytes else array, options_zstd.level)) |
76358 | 271 |
} |
64004 | 272 |
} |
68167 | 273 |
|
75393 | 274 |
def maybe_compress( |
76351
2cee31cd92f0
generic support for XZ and Zstd compression in Isabelle/Scala;
wenzelm
parents:
76350
diff
changeset
|
275 |
options: Compress.Options = Compress.Options(), |
2cee31cd92f0
generic support for XZ and Zstd compression in Isabelle/Scala;
wenzelm
parents:
76350
diff
changeset
|
276 |
cache: Compress.Cache = Compress.Cache.none |
75393 | 277 |
) : (Boolean, Bytes) = { |
68167 | 278 |
val compressed = compress(options = options, cache = cache) |
279 |
if (compressed.length < length) (true, compressed) else (false, this) |
|
280 |
} |
|
54439 | 281 |
} |