Skip to content

API: Added utilities to operate on blob streams as stdio FILEs#255

Open
snej wants to merge 3 commits intomasterfrom
feature/blobFILE
Open

API: Added utilities to operate on blob streams as stdio FILEs#255
snej wants to merge 3 commits intomasterfrom
feature/blobFILE

Conversation

@snej
Copy link
Copy Markdown
Contributor

@snej snej commented Dec 2, 2021

This lets you read and write blobs using standard C functions like fread, fseek, fwrite, similarly to the way other CBL platforms let you use the platform's stream classes.

The API is in src/CBLBlob+FILE.h. This is not in the include/cbl directory since it isn't (yet?) official API.

Unfortunately I was unable to find a way to implement this on Windows, since (apparently?) it does not have a function equivalent to funopen or fopencookie for creating a FILE* with custom I/O callbacks. Still, it seems a shame to leave out this feature, especially since the majority of CBL-C clients will probably be Linux-based.

@borrrden
Copy link
Copy Markdown
Member

borrrden commented Dec 3, 2021

This looks like it might be helpful -> https://github.com/Snaipe/fmem

Header is not in the `include/cbl` directory since this isn't
official API.
@snej
Copy link
Copy Markdown
Contributor Author

snej commented Jan 4, 2022

fmem only provides a FILE that reads/writes a memory buffer. If we used that, the memory usage would be the same as our non-stream-based blob API, since the entire blob would have to exist in memory.

@snej snej force-pushed the feature/blobFILE branch from 02a1299 to 016a8b6 Compare January 5, 2022 20:07
@pasin
Copy link
Copy Markdown
Contributor

pasin commented Jan 10, 2022

The build is failing now. Should be #include "CBLBlob+FILE.h" instead of "CBLBlob+File.h".

/Users/runner/work/couchbase-lite-C/couchbase-lite-C/test/BlobTest.cc:20:10: warning: non-portable path to file '"CBLBlob+FILE.h"'; specified path differs in case from file name on disk [-Wnonportable-include-path]
#include "CBLBlob+File.h"
         ^~~~~~~~~~~~~~~~
         "CBLBlob+FILE.h"
In file included from /Users/runner/work/couchbase-lite-C/couchbase-lite-C/test/BlobTest.cc:20:
/Users/runner/work/couchbase-lite-C/couchbase-lite-C/test/../src/CBLBlob+File.h:20:10: fatal error: 'CBLBlob.h' file not found
#include "CBLBlob.h"
         ^~~~~~~~~~~
1 warning and 1 error generated.
make[2]: *** [test/CMakeFiles/CBL_C_Tests.dir/BlobTest.cc.o] Error 1
make[1]: *** [test/CMakeFiles/CBL_C_Tests.dir/all] Error 2
make: *** [all] Error 2
Error: Process completed with exit code 2.

@frank-dspeed
Copy link
Copy Markdown

yes keep that work up as the WSL on windows allows that also i guess even cygwin allows that we also use that to binary pipe blobs into chrome on windows via the devtools protocol and this is a nice feat as it will allow my wasm implementation to take browser blobs directly in and out that makes streaming to the couchbase cluster via direct socket api experiment that we currently run much more nice.

Only for your interrest i am building a poc that directly uses current chromium dev the feat is already included to directly connect via the couchbase sdk to a couchbase cluster anyway i also build cblite to wasm and i am using then the binary in and output

it would help me if you could maybe make the fleece api run able more isolated so that i could create cblite with indexdb to run complet in the browser.

@pasin
Copy link
Copy Markdown
Contributor

pasin commented Jun 15, 2022

@snej Can you check the build failure?

@frank-dspeed
Copy link
Copy Markdown

@pasin please use the latest version and tell me if that happens with that also

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants