MCPcopy Create free account
hub / github.com/deathkiller/jazz2-native / WriteInternal

Method WriteInternal

Sources/Shared/IO/Compression/ZstdStream.cpp:410–450  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

408 }
409
410 std::int32_t ZstdWriter::WriteInternal(const void* buffer, std::int32_t bytesToWrite, bool finish)
411 {
412 if (bytesToWrite > 0) {
413 if (bytesToWrite > _inBufferCapacity) {
414 bytesToWrite = _inBufferCapacity;
415 }
416
417 ZSTD_inBuffer inBuffer = { buffer, bytesToWrite, 0 };
418 ZSTD_outBuffer outBuffer = { &_buffer[0], _outBufferCapacity, 0 };
419 std::size_t result = ZSTD_compressStream(_strm, &outBuffer, &inBuffer);
420 if (ZSTD_isError(result)) {
421#if defined(DEATH_TRACE_VERBOSE_IO)
422 LOGE("ZSTD_compressStream() failed with error 0x{:x} ({})", result, ZSTD_getErrorName(result));
423#endif
424 _state = State::Failed;
425 return Stream::Invalid;
426 }
427
428 if (outBuffer.pos > 0) {
429 _outputStream->Write(&_buffer[0], outBuffer.pos);
430 }
431
432 bytesToWrite = inBuffer.pos;
433 }
434
435 if (finish) {
436 ZSTD_outBuffer outBuffer = { &_buffer[0], _outBufferCapacity, 0 };
437 std::size_t result = ZSTD_endStream(_strm, &outBuffer);
438 if (ZSTD_isError(result)) {
439#if defined(DEATH_TRACE_VERBOSE_IO)
440 LOGE("ZSTD_endStream() failed with error 0x{:x} ({})", result, ZSTD_getErrorName(result));
441#endif
442 _state = State::Failed;
443 return Stream::Invalid;
444 }
445
446 _outputStream->Write(&_buffer[0], outBuffer.pos);
447 }
448
449 return bytesToWrite;
450 }
451
452}}}
453

Callers

nothing calls this directly

Calls 1

WriteMethod · 0.45

Tested by

no test coverage detected