Bug 1831122 [wpt PR 39823] - Update wpt metadata, a=testonly
[gecko.git] / dom / indexedDB / IndexedDBCommon.cpp
blob63a6fd2fb6380e399c5abaedeec840e057ee1b76
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/. */
7 #include "IndexedDBCommon.h"
9 #include "js/StructuredClone.h"
10 #include "mozilla/SnappyUncompressInputStream.h"
12 namespace mozilla::dom::indexedDB {
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);
22 char buffer[kFileCopyBufferSize];
24 QM_TRY(CollectEach(
25 [&snappyInputStream = *snappyInputStream, &buffer] {
26 QM_TRY_RETURN(MOZ_TO_RESULT_INVOKE_MEMBER(snappyInputStream, Read,
27 buffer, sizeof(buffer)));
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));
34 return Ok{};
35 }));
37 return NS_OK;
40 } // namespace mozilla::dom::indexedDB