You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@opendal.apache.org by "silver-ymz (via GitHub)" <gi...@apache.org> on 2025/06/09 06:28:14 UTC
Re: [PR] feat(bindings/haskell): add more api [opendal]
silver-ymz commented on code in PR #6264:
URL: https://github.com/apache/opendal/pull/6264#discussion_r2135090399
##########
bindings/haskell/haskell-src/OpenDAL.hs:
##########
@@ -558,3 +602,130 @@ nextLister (Lister lister) = withForeignPtr lister $ \listerptr ->
let code = parseErrorCode $ fromIntegral $ ffiCode ffiResult
errMsg <- peekCString (errorMessage ffiResult)
return $ Left $ OpenDALError code errMsg
+
+-- | Append bytes to given path.
+appendOpRaw :: Operator -> String -> ByteString -> IO (Either OpenDALError ())
+appendOpRaw (Operator op) path byte = withForeignPtr op $ \opptr ->
+ withCString path $ \cPath ->
+ BS.useAsCStringLen byte $ \(cByte, len) ->
+ alloca $ \ffiResultPtr -> do
+ c_blocking_append opptr cPath cByte (fromIntegral len) ffiResultPtr
+ ffiResult <- peek ffiResultPtr
+ if ffiCode ffiResult == 0
+ then return $ Right ()
+ else do
+ let code = parseErrorCode $ fromIntegral $ ffiCode ffiResult
+ errMsg <- peekCString (errorMessage ffiResult)
+ return $ Left $ OpenDALError code errMsg
+
+-- | Creates a new OpenDAL writer via `Operator`.
+newWriter :: Operator -> String -> IO (Either OpenDALError Writer)
+newWriter (Operator op) path = withForeignPtr op $ \opptr ->
+ withCString path $ \cPath ->
+ alloca $ \ffiResultPtr -> do
+ c_blocking_writer opptr cPath ffiResultPtr
+ ffiResult <- peek ffiResultPtr
+ if ffiCode ffiResult == 0
+ then do
+ ffiwriter <- peek $ dataPtr ffiResult
+ writer <- Writer <$> newForeignPtr c_free_writer ffiwriter
+ return $ Right writer
+ else do
+ let code = parseErrorCode $ fromIntegral $ ffiCode ffiResult
+ errMsg <- peekCString (errorMessage ffiResult)
+ return $ Left $ OpenDALError code errMsg
+
+-- | Creates a new OpenDAL writer append via `Operator`.
+newWriterAppend :: Operator -> String -> IO (Either OpenDALError Writer)
+newWriterAppend (Operator op) path = withForeignPtr op $ \opptr ->
+ withCString path $ \cPath ->
+ alloca $ \ffiResultPtr -> do
+ c_blocking_writer_append opptr cPath ffiResultPtr
+ ffiResult <- peek ffiResultPtr
+ if ffiCode ffiResult == 0
+ then do
+ ffiwriter <- peek $ dataPtr ffiResult
+ writer <- Writer <$> newForeignPtr c_free_writer ffiwriter
+ return $ Right writer
Review Comment:
`newWriter`, `newWriterAppend` and `writerOpRaw` are kind of duplicated for users. Maybe a better solution is exporting `WriterOption` struct and only keeping
`writerOpRaw :: Operator -> String -> WriterOption -> IO (Either OpenDALError Writer)`
##########
bindings/haskell/haskell-src/OpenDAL.hs:
##########
@@ -210,19 +225,25 @@ class (Monad m) => MonadOperation m where
-- | Delete given path.
deleteOp :: String -> m ()
- -- | Get given path’s metadata without cache directly.
+ -- | Get given path's metadata without cache directly.
statOp :: String -> m Metadata
-- | List current dir path.
-- This function will create a new handle to list entries.
- -- An error will be returned if path doesn’t end with /.
+ -- An error will be returned if path doesn't end with /.
listOp :: String -> m Lister
-- | List dir in flat way.
-- Also, this function can be used to list a prefix.
- -- An error will be returned if given path doesn’t end with /.
+ -- An error will be returned if given path doesn't end with /.
scanOp :: String -> m Lister
+ -- | Append bytes to given path.
+ appendOp :: String -> ByteString -> m ()
Review Comment:
`append` is not an atomic operation and it isn't in OpenDAL Rust API. We shouldn't export `append` API and leave relative logic to users.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@opendal.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org