summaryrefslogtreecommitdiff
path: root/core/fxcodec/codec/cfx_codec_memory.cpp
blob: b8cf97b0984a4be0d6985d2be421c857fb76b629 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// Copyright 2018 PDFium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "core/fxcodec/codec/cfx_codec_memory.h"

#include <algorithm>

CFX_CodecMemory::CFX_CodecMemory(pdfium::span<uint8_t> buffer)
    : buffer_(buffer) {}

CFX_CodecMemory::~CFX_CodecMemory() = default;

bool CFX_CodecMemory::Seek(size_t pos) {
  if (pos > buffer_.size())
    return false;

  pos_ = pos;
  return true;
}

size_t CFX_CodecMemory::ReadBlock(void* buffer, size_t size) {
  if (!buffer || !size || IsEOF())
    return 0;

  size_t bytes_to_read = std::min(size, buffer_.size() - pos_);
  memcpy(buffer, &buffer_[pos_], bytes_to_read);
  pos_ += bytes_to_read;
  return bytes_to_read;
}