Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Classes | Functions
SkStreamPriv.h File Reference
#include "include/core/SkRefCnt.h"
#include "include/core/SkStream.h"

Go to the source code of this file.

Classes

class  SkDebugfStream
 

Functions

sk_sp< SkDataSkCopyStreamToData (SkStream *stream)
 
bool SkStreamCopy (SkWStream *out, SkStream *input)
 
bool StreamRemainingLengthIsBelow (SkStream *stream, size_t len)
 

Function Documentation

◆ SkCopyStreamToData()

sk_sp< SkData > SkCopyStreamToData ( SkStream stream)

Copy the provided stream to an SkData variable.

Note: Assumes the stream is at the beginning. If it has a length, but is not at the beginning, this call will fail (return NULL).

Parameters
streamSkStream to be copied into data.
Returns
The resulting SkData after the copy, nullptr on failure.

Definition at line 937 of file SkStream.cpp.

937 {
938 SkASSERT(stream != nullptr);
939
940 if (stream->hasLength()) {
941 return SkData::MakeFromStream(stream, stream->getLength());
942 }
943
944 SkDynamicMemoryWStream tempStream;
945 const size_t bufferSize = 4096;
946 char buffer[bufferSize];
947 do {
948 size_t bytesRead = stream->read(buffer, bufferSize);
949 tempStream.write(buffer, bytesRead);
950 } while (!stream->isAtEnd());
951 return tempStream.detachAsData();
952}
#define SkASSERT(cond)
Definition SkAssert.h:116
static sk_sp< SkData > MakeFromStream(SkStream *, size_t size)
Definition SkData.cpp:208
bool write(const void *buffer, size_t size) override
Definition SkStream.cpp:535
sk_sp< SkData > detachAsData()
Definition SkStream.cpp:707
static const uint8_t buffer[]

◆ SkStreamCopy()

bool SkStreamCopy ( SkWStream out,
SkStream input 
)

Copies the input stream from the current position to the end. Does not rewind the input stream.

Definition at line 954 of file SkStream.cpp.

954 {
955 const char* base = static_cast<const char*>(input->getMemoryBase());
956 if (base && input->hasPosition() && input->hasLength()) {
957 // Shortcut that avoids the while loop.
958 size_t position = input->getPosition();
959 size_t length = input->getLength();
960 SkASSERT(length >= position);
961 return out->write(&base[position], length - position);
962 }
963 char scratch[4096];
964 size_t count;
965 while (true) {
966 count = input->read(scratch, sizeof(scratch));
967 if (0 == count) {
968 return true;
969 }
970 if (!out->write(scratch, count)) {
971 return false;
972 }
973 }
974}
int count
virtual bool hasPosition() const
Definition SkStream.h:117
virtual size_t getPosition() const
Definition SkStream.h:119
virtual size_t getLength() const
Definition SkStream.h:137
virtual const void * getMemoryBase()
Definition SkStream.h:141
virtual bool hasLength() const
Definition SkStream.h:135
virtual size_t read(void *buffer, size_t size)=0
size_t length

◆ StreamRemainingLengthIsBelow()

bool StreamRemainingLengthIsBelow ( SkStream stream,
size_t  len 
)

Definition at line 976 of file SkStream.cpp.

976 {
977 SkASSERT(stream);
978 if (stream->hasLength()) {
979 if (stream->hasPosition()) {
980 size_t remainingBytes = stream->getLength() - stream->getPosition();
981 return remainingBytes < len;
982 }
983 // We don't know the position, but we can still return true if the
984 // stream's entire length is shorter than the requested length.
985 return stream->getLength() < len;
986 }
987 return false;
988}