gpt4 book ai didi

c++ - Azure C++ 库 : "Invalid streambuf object"

转载 作者:行者123 更新时间:2023-11-30 04:58:38 25 4
gpt4 key购买 nike

我正在尝试使用 C++ Azure 客户端库下载一个可能巨大的 Azure block blob。它不起作用,因为我不知道如何使用缓冲区大小初始化 concurrency::streams::streambuf 对象。我的代码如下所示:

 // Assume blockBlob has been created correctly.
concurrency::streams::istream blobStream = blockBlob.open_read();
// I don't know how to initialize this streambuf:
concurrency::streams::streambuf<uint8_t> dlStreamBuf;
size_t nBytesReturned = 0, nBytesToRead = 65536;
do {
// This gets the exception "Invalid streambuf object":
concurrency::task<size_t> returnedTask = blobStream.read(dlStreamBuf, nBytesToRead);
nBytesReturned = returnedTask.get();
bytesSoFar += nBytesReturned;
// Process the data in dlStreamBuf here...
} while(nBytesReturned > 0);
blobStream.close();

请注意,不要将上述 Streambuf 与标准 C++ Streambuf 混淆。

任何人都可以告诉我如何正确构造和初始化 concurrency::streams::streambuf 吗?

谢谢。

最佳答案

streambuf 似乎是一个模板类。试试这个:

    concurrency::streams::container_buffer<std::vector<uint8_t>> output_buffer;
size_t nBytesReturned = 0, nBytesToRead = 65536;
do {
// This gets the exception "Invalid streambuf object":
concurrency::task<size_t> returnedTask = stream.read(output_buffer, nBytesToRead);
nBytesReturned = returnedTask.get();
bytesSoFar += nBytesReturned;
// Process the data in dlStreamBuf here...
} while (nBytesReturned > 0);
stream.close();

示例代码在这里:https://github.com/Azure/azure-storage-cpp/blob/76cb553249ede1e6f05456d936c9a36753cc1597/Microsoft.WindowsAzure.Storage/tests/blob_streams_test.cpp#L192

关于c++ - Azure C++ 库 : "Invalid streambuf object",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51621224/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com