Skip to content

Commit 9c3386d

Browse files
Long9725luben
authored andcommitted
fix: compress & decompress DirectByteBufferStream error is always ZSTD_error_no_error
1 parent 7de4360 commit 9c3386d

File tree

3 files changed

+4
-3
lines changed

3 files changed

+4
-3
lines changed

src/main/java/com/github/luben/zstd/ZstdCompressCtx.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ public boolean compressDirectByteBufferStream(ByteBuffer dst, ByteBuffer src, En
502502
try {
503503
long result = compressDirectByteBufferStream0(nativePtr, dst, dst.position(), dst.limit(), src, src.position(), src.limit(), endOp.value());
504504
if ((result & 0x80000000L) != 0) {
505-
long code = result & 0xFF;
505+
long code = -(result & 0xFF);
506506
throw new ZstdException(code, Zstd.getErrorName(code));
507507
}
508508
src.position((int)(result & 0x7FFFFFFF));

src/main/java/com/github/luben/zstd/ZstdDecompressCtx.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ public boolean decompressDirectByteBufferStream(ByteBuffer dst, ByteBuffer src)
137137
try {
138138
long result = decompressDirectByteBufferStream0(nativePtr, dst, dst.position(), dst.limit(), src, src.position(), src.limit());
139139
if ((result & 0x80000000L) != 0) {
140-
long code = result & 0xFF;
140+
long code = -(result & 0xFF);
141141
throw new ZstdException(code, Zstd.getErrorName(code));
142142
}
143143
src.position((int) (result & 0x7FFFFFFF));

src/test/scala/Zstd.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1486,7 +1486,8 @@ class ZstdSpec extends AnyFlatSpec with ScalaCheckPropertyChecks {
14861486
cctx.compressDirectByteBufferStream(compressedBuffer, inputBuffer, EndDirective.END)
14871487
fail("compression succeeded, but should have failed")
14881488
} catch {
1489-
case _: ZstdException => // compression should throw a ZstdException
1489+
case ex: ZstdException => // compression should throw a ZstdException
1490+
assert(ex.getErrorCode == -106)
14901491
}
14911492
}
14921493
}

0 commit comments

Comments
 (0)