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 #ifndef SkDataUtils_DEFINED | |
9 #define SkDataUtils_DEFINED | |
10 | |
11 #include "SkData.h" | |
12 #include "SkStream.h" | |
13 | |
14 /** | |
15 * Static class that performs various operations on SkData objects. | |
16 * | |
17 * EPOGER: Before committing, add unittests for these methods. | |
18 * | |
19 * TODO(epoger): Move these methods into SkStream.[cpp|h], as attempted in | |
20 * https://codereview.appspot.com/7300071 ? | |
21 */ | |
22 class SkDataUtils { | |
23 public: | |
24 /** | |
25 * Read as many bytes as possible (up to maxBytes) from the stream into | |
26 * an SkData object. | |
27 * | |
28 * If the returned SkData contains fewer than maxBytes, then EOF has been | |
29 * reached and no more data would be available from subsequent calls. | |
30 * (If EOF has already been reached, then this call will return an empty | |
31 * SkData object immediately.) | |
32 * | |
33 * If there are fewer than maxBytes bytes available to read from the | |
34 * stream, but the stream has not been closed yet, this call will block | |
35 * until there are enough bytes to read or the stream has been closed. | |
36 * | |
37 * It is up to the caller to call unref() on the returned SkData object | |
38 * once the data is no longer needed, so that the underlying buffer will | |
39 * be freed. For example: | |
40 * | |
41 * { | |
42 * size_t maxBytes = 256; | |
43 * SkAutoDataUnref dataRef(readIntoSkData(stream, maxBytes)); | |
44 * if (NULL != dataRef.get()) { | |
45 * size_t bytesActuallyRead = dataRef.get()->size(); | |
46 * // use the data... | |
47 * } | |
48 * } | |
49 * // underlying buffer has been freed, thanks to auto unref | |
50 */ | |
51 static SkData* ReadIntoSkData(SkStream &stream, size_t maxBytes); | |
52 | |
53 /** | |
54 * Wrapper around ReadIntoSkData for files: reads the entire file into | |
55 * an SkData object. | |
56 */ | |
57 static SkData* ReadFileIntoSkData(SkFILEStream &stream) { | |
58 return ReadIntoSkData(stream, stream.getLength()); | |
59 } | |
60 | |
61 }; | |
62 | |
63 #endif | |
OLD | NEW |