OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright 2014 Google Inc. | |
3 * | |
4 * Use of this source code is governed by a BSD-style license that can be | |
5 * found in the LICENSE file. | |
6 */ | |
7 | |
8 #include "SkData.h" | |
9 #include "SkDataUtils.h" | |
10 #include "SkStream.h" | |
11 | |
12 /*static*/ SkData* SkDataUtils::ReadIntoSkData(SkStream &stream, size_t maxBytes
) { | |
13 if (0 == maxBytes) { | |
14 return SkData::NewEmpty(); | |
15 } | |
16 char* bufStart = reinterpret_cast<char *>(sk_malloc_throw(maxBytes)); | |
17 char* bufPtr = bufStart; | |
18 size_t bytesRemaining = maxBytes; | |
19 while (bytesRemaining > 0) { | |
20 size_t bytesReadThisTime = stream.read(bufPtr, bytesRemaining); | |
21 if (0 == bytesReadThisTime) { | |
22 break; | |
23 } | |
24 bytesRemaining -= bytesReadThisTime; | |
25 bufPtr += bytesReadThisTime; | |
26 } | |
27 return SkData::NewFromMalloc(bufStart, maxBytes - bytesRemaining); | |
28 } | |
OLD | NEW |