Add removeObject function (#22)

* Add an example
 * Fix minor issues in API.md
This commit is contained in:
Krishnan Parthasarathi 2017-03-02 16:49:27 +05:30 committed by Aditya Manthramurthy
parent 7be42dd011
commit de97837020
4 changed files with 104 additions and 22 deletions

View File

@ -120,6 +120,8 @@ The `runMinio` function performs the provided action in the `Minio`
monad and returns a `ResourceT IO (Either MinioErr a)` value:
``` haskell
{-# Language OverloadedStrings #-}
import Network.Minio
main :: IO ()
@ -180,6 +182,7 @@ __Example__
``` haskell
{-# Language OverloadedStrings #-}
main :: IO ()
main = do
res <- runResourceT $ runMinio minioPlayCI $ do
@ -210,6 +213,7 @@ __Example__
``` haskell
{-# Language OverloadedStrings #-}
main :: IO ()
main = do
res <- runResourceT $ runMinio minioPlayCI $ do
@ -256,7 +260,9 @@ __ObjectInfo record type__
__Example__
``` haskell
import Data.Conduit ($$)
{-# Language OverloadedStrings #-}
import Data.Conduit (($$))
import Conduit.Combinators (sinkList)
main :: IO ()
@ -305,7 +311,9 @@ __UploadInfo record type__
__Example__
```haskell
import Data.Conduit ($$)
{-# Language OverloadedStrings #-}
import Data.Conduit (($$))
import Conduit.Combinators (sinkList)
main :: IO ()
@ -342,7 +350,6 @@ __Return Value__
The return value can be incrementally read to process the contents of
the object.
|Return type |Description |
|:---|:---|
| _C.ResumableSource Minio ByteString_ | A Conduit ResumableSource of `ByteString` values. |
@ -350,9 +357,12 @@ the object.
__Example__
```haskell
{-# Language OverloadedStrings #-}
import Data.Conduit ($$+-)
import Network.Minio
import Data.Conduit (($$+-))
import Data.Conduit.Binary (sinkLbs)
import qualified Data.ByteString.Lazy as LB
main :: IO ()
main = do
@ -364,11 +374,13 @@ main = do
-- bucket, object and upload ID.
res <- runResourceT $ runMinio minioPlayCI $ do
source <- getObject bucket object
src $$+- sinkLbs
source $$+- sinkLbs
-- the following the prints the contents of the object.
print res
putStrLn $ either
(("Failed to getObject: " ++) . show)
(("Read an object of length: " ++) . show . LB.length)
res
```
<a name="putObject"></a>
@ -385,7 +397,37 @@ main = do
<a name="removeObject"></a>
### removeObject :: Bucket -> Object -> Minio ()
Removes an object from the service
__Parameters__
In the expression `removeObject bucketName objectName` the parameters
are:
|Param |Type |Description |
|:---|:---| :---|
| `bucketName` | _Bucket_ (alias for `Text`) | Name of the bucket |
| `objectName` | _Object_ (alias for `Text`) | Name of the object |
__Example__
```haskell
{-# Language OverloadedStrings #-}
import Network.Minio
main :: IO ()
main = do
let
bucket = "mybucket"
object = "myobject"
res <- runResourceT $ runMinio minioPlayCI $ do
removeObject bucket object
case res of
Left e -> putStrLn $ "Failed to remove " ++ show bucket ++ "/" ++ show object
Right _ -> putStrLn "Removed object successfully"
```
<!-- ## 4. Presigned operations -->

35
examples/RemoveObject.hs Executable file
View File

@ -0,0 +1,35 @@
#!/usr/bin/env stack
-- stack --resolver lts-6.27 runghc --package minio-hs
--
-- Minio Haskell SDK, (C) 2017 Minio, Inc.
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
--
{-# Language OverloadedStrings #-}
import Network.Minio
main :: IO ()
main = do
let
bucket = "mybucket"
object = "myobject"
res <- runResourceT $ runMinio minioPlayCI $ do
removeObject bucket object
case res of
Left e -> putStrLn $ "Failed to remove " ++ show bucket ++ "/" ++ show object
Right _ -> putStrLn "Removed object successfully"

View File

@ -64,6 +64,7 @@ module Network.Minio
, fPutObject
, putObject
, copyObject
, removeObject
, getObject
, statObject
@ -121,10 +122,18 @@ putObject bucket object src sizeMay =
copyObject :: Bucket -> Object -> CopyPartSource -> Minio ()
copyObject bucket object cps = void $ copyObjectInternal bucket object cps
-- | Remove an object from the object store.
removeObject :: Bucket -> Object -> Minio ()
removeObject = deleteObject
-- | Get an object from the object store as a resumable source (conduit).
getObject :: Bucket -> Object -> Minio (C.ResumableSource Minio ByteString)
getObject bucket object = snd <$> getObject' bucket object [] []
-- | Get an object's metadata from the object store.
statObject :: Bucket -> Object -> Minio ObjectInfo
statObject bucket object = headObject bucket object
-- | Creates a new bucket in the object store. The Region can be
-- optionally specified. If not specified, it will use the region
-- configured in ConnectInfo, which is by default, the US Standard
@ -135,11 +144,7 @@ makeBucket bucket regionMay= do
putBucket bucket region
modify (Map.insert bucket region)
-- | Get an object's metadata from the object store.
statObject :: Bucket -> Object -> Minio ObjectInfo
statObject bucket object = headObject bucket object
removeBucket :: Bucket -> Minio()
removeBucket :: Bucket -> Minio ()
removeBucket bucket = do
deleteBucket bucket
modify (Map.delete bucket)

View File

@ -160,7 +160,7 @@ liveServerUnitTests = testGroup "Unit tests against a live server"
"Wrong file size of put file after getting"
step $ "Cleanup actions"
deleteObject bucket object
removeObject bucket object
-- putObject test (conduit source, no size specified)
let obj = "mpart"
@ -194,7 +194,7 @@ liveServerUnitTests = testGroup "Unit tests against a live server"
"Wrong file size of put file after getting"
step $ "Cleanup actions"
deleteObject bucket obj
removeObject bucket obj
step "Prepare for putObjectInternal with large file as source."
step "upload large object"
@ -202,7 +202,7 @@ liveServerUnitTests = testGroup "Unit tests against a live server"
Just $ 1024*1024*100)
step "cleanup"
deleteObject bucket "big"
removeObject bucket "big"
, funTestWithBucket "Listing Test" $ \step bucket -> do
@ -274,7 +274,7 @@ liveServerUnitTests = testGroup "Unit tests against a live server"
step "Cleanup actions"
forM_ expected $
\obj -> deleteObject bucket obj
\obj -> removeObject bucket obj
step "High-level listIncompleteUploads Test"
let object = "newmpupload"
@ -336,8 +336,8 @@ liveServerUnitTests = testGroup "Unit tests against a live server"
"Copied object did not match expected."
step "cleanup actions"
deleteObject bucket object
deleteObject bucket objCopy
removeObject bucket object
removeObject bucket objCopy
step "copyObjectPart basic tests"
let srcObj = "XXX"
@ -370,8 +370,8 @@ liveServerUnitTests = testGroup "Unit tests against a live server"
liftIO $ (s == mb15) @? "Size failed to match"
step $ "Cleanup actions"
deleteObject bucket srcObj
deleteObject bucket copyObj
removeObject bucket srcObj
removeObject bucket copyObj
step "copyObject basic tests"
let srcs = ["XXX", "XXXL"]
@ -391,7 +391,7 @@ liveServerUnitTests = testGroup "Unit tests against a live server"
liftIO $ (sizes == uploadedSizes) @? "Uploaded obj sizes failed to match"
forM_ (concat [srcs, copyObjs]) (deleteObject bucket)
forM_ (concat [srcs, copyObjs]) (removeObject bucket)
step "copyObject with offset test "
let src = "XXX"
@ -412,5 +412,5 @@ liveServerUnitTests = testGroup "Unit tests against a live server"
liftIO $ (cSize == 10 * 1024 * 1024) @? "Uploaded obj size mismatched!"
forM_ [src, copyObj] (deleteObject bucket)
forM_ [src, copyObj] (removeObject bucket)
]