IndexedDBCommon.cpp (1480B)
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */ 3 /* This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 #include "IndexedDBCommon.h" 8 9 #include "js/StructuredClone.h" 10 #include "mozilla/SnappyUncompressInputStream.h" 11 12 namespace mozilla::dom::indexedDB { 13 14 // aStructuredCloneData is a parameter rather than a return value because one 15 // caller preallocates it on the heap not immediately before calling for some 16 // reason. Maybe this could be changed. 17 nsresult SnappyUncompressStructuredCloneData( 18 nsIInputStream& aInputStream, JSStructuredCloneData& aStructuredCloneData) { 19 const auto snappyInputStream = 20 MakeRefPtr<SnappyUncompressInputStream>(&aInputStream); 21 22 char buffer[kFileCopyBufferSize]; 23 24 QM_TRY(CollectEach( 25 [&snappyInputStream = *snappyInputStream, &buffer] { 26 QM_TRY_RETURN(MOZ_TO_RESULT_INVOKE_MEMBER(snappyInputStream, Read, 27 buffer, sizeof(buffer))); 28 }, 29 [&aStructuredCloneData, 30 &buffer](const uint32_t& numRead) -> Result<Ok, nsresult> { 31 QM_TRY(OkIf(aStructuredCloneData.AppendBytes(buffer, numRead)), 32 Err(NS_ERROR_OUT_OF_MEMORY)); 33 34 return Ok{}; 35 })); 36 37 return NS_OK; 38 } 39 40 } // namespace mozilla::dom::indexedDB