Thu, 15 Jan 2015 21:03:48 +0100
Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)
1 /*
2 * Copyright 2013 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 */
8 #include "SkStream.h"
9 #include "SkStreamHelpers.h"
10 #include "SkTypes.h"
12 size_t CopyStreamToStorage(SkAutoMalloc* storage, SkStream* stream) {
13 SkASSERT(storage != NULL);
14 SkASSERT(stream != NULL);
16 if (stream->hasLength()) {
17 const size_t length = stream->getLength();
18 void* dst = storage->reset(length);
19 if (stream->read(dst, length) != length) {
20 return 0;
21 }
22 return length;
23 }
25 SkDynamicMemoryWStream tempStream;
26 // Arbitrary buffer size.
27 const size_t bufferSize = 256 * 1024; // 256KB
28 char buffer[bufferSize];
29 SkDEBUGCODE(size_t debugLength = 0;)
30 do {
31 size_t bytesRead = stream->read(buffer, bufferSize);
32 tempStream.write(buffer, bytesRead);
33 SkDEBUGCODE(debugLength += bytesRead);
34 SkASSERT(tempStream.bytesWritten() == debugLength);
35 } while (!stream->isAtEnd());
36 const size_t length = tempStream.bytesWritten();
37 void* dst = storage->reset(length);
38 tempStream.copyTo(dst);
39 return length;
40 }