Add removeObject function (#22)
* Add an example * Fix minor issues in API.md
This commit is contained in:
parent
7be42dd011
commit
de97837020
56
docs/API.md
56
docs/API.md
@ -120,6 +120,8 @@ The `runMinio` function performs the provided action in the `Minio`
|
|||||||
monad and returns a `ResourceT IO (Either MinioErr a)` value:
|
monad and returns a `ResourceT IO (Either MinioErr a)` value:
|
||||||
|
|
||||||
``` haskell
|
``` haskell
|
||||||
|
{-# Language OverloadedStrings #-}
|
||||||
|
|
||||||
import Network.Minio
|
import Network.Minio
|
||||||
|
|
||||||
main :: IO ()
|
main :: IO ()
|
||||||
@ -180,6 +182,7 @@ __Example__
|
|||||||
|
|
||||||
``` haskell
|
``` haskell
|
||||||
{-# Language OverloadedStrings #-}
|
{-# Language OverloadedStrings #-}
|
||||||
|
|
||||||
main :: IO ()
|
main :: IO ()
|
||||||
main = do
|
main = do
|
||||||
res <- runResourceT $ runMinio minioPlayCI $ do
|
res <- runResourceT $ runMinio minioPlayCI $ do
|
||||||
@ -210,6 +213,7 @@ __Example__
|
|||||||
|
|
||||||
``` haskell
|
``` haskell
|
||||||
{-# Language OverloadedStrings #-}
|
{-# Language OverloadedStrings #-}
|
||||||
|
|
||||||
main :: IO ()
|
main :: IO ()
|
||||||
main = do
|
main = do
|
||||||
res <- runResourceT $ runMinio minioPlayCI $ do
|
res <- runResourceT $ runMinio minioPlayCI $ do
|
||||||
@ -256,7 +260,9 @@ __ObjectInfo record type__
|
|||||||
__Example__
|
__Example__
|
||||||
|
|
||||||
``` haskell
|
``` haskell
|
||||||
import Data.Conduit ($$)
|
{-# Language OverloadedStrings #-}
|
||||||
|
|
||||||
|
import Data.Conduit (($$))
|
||||||
import Conduit.Combinators (sinkList)
|
import Conduit.Combinators (sinkList)
|
||||||
|
|
||||||
main :: IO ()
|
main :: IO ()
|
||||||
@ -305,7 +311,9 @@ __UploadInfo record type__
|
|||||||
__Example__
|
__Example__
|
||||||
|
|
||||||
```haskell
|
```haskell
|
||||||
import Data.Conduit ($$)
|
{-# Language OverloadedStrings #-}
|
||||||
|
|
||||||
|
import Data.Conduit (($$))
|
||||||
import Conduit.Combinators (sinkList)
|
import Conduit.Combinators (sinkList)
|
||||||
|
|
||||||
main :: IO ()
|
main :: IO ()
|
||||||
@ -342,7 +350,6 @@ __Return Value__
|
|||||||
|
|
||||||
The return value can be incrementally read to process the contents of
|
The return value can be incrementally read to process the contents of
|
||||||
the object.
|
the object.
|
||||||
|
|
||||||
|Return type |Description |
|
|Return type |Description |
|
||||||
|:---|:---|
|
|:---|:---|
|
||||||
| _C.ResumableSource Minio ByteString_ | A Conduit ResumableSource of `ByteString` values. |
|
| _C.ResumableSource Minio ByteString_ | A Conduit ResumableSource of `ByteString` values. |
|
||||||
@ -350,9 +357,12 @@ the object.
|
|||||||
__Example__
|
__Example__
|
||||||
|
|
||||||
```haskell
|
```haskell
|
||||||
|
{-# Language OverloadedStrings #-}
|
||||||
|
|
||||||
import Data.Conduit ($$+-)
|
import Network.Minio
|
||||||
|
import Data.Conduit (($$+-))
|
||||||
import Data.Conduit.Binary (sinkLbs)
|
import Data.Conduit.Binary (sinkLbs)
|
||||||
|
import qualified Data.ByteString.Lazy as LB
|
||||||
|
|
||||||
main :: IO ()
|
main :: IO ()
|
||||||
main = do
|
main = do
|
||||||
@ -364,11 +374,13 @@ main = do
|
|||||||
-- bucket, object and upload ID.
|
-- bucket, object and upload ID.
|
||||||
res <- runResourceT $ runMinio minioPlayCI $ do
|
res <- runResourceT $ runMinio minioPlayCI $ do
|
||||||
source <- getObject bucket object
|
source <- getObject bucket object
|
||||||
src $$+- sinkLbs
|
source $$+- sinkLbs
|
||||||
|
|
||||||
-- the following the prints the contents of the object.
|
-- 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>
|
<a name="putObject"></a>
|
||||||
@ -385,7 +397,37 @@ main = do
|
|||||||
|
|
||||||
<a name="removeObject"></a>
|
<a name="removeObject"></a>
|
||||||
### removeObject :: Bucket -> Object -> Minio ()
|
### 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 -->
|
<!-- ## 4. Presigned operations -->
|
||||||
|
|
||||||
|
|||||||
35
examples/RemoveObject.hs
Executable file
35
examples/RemoveObject.hs
Executable 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"
|
||||||
@ -64,6 +64,7 @@ module Network.Minio
|
|||||||
, fPutObject
|
, fPutObject
|
||||||
, putObject
|
, putObject
|
||||||
, copyObject
|
, copyObject
|
||||||
|
, removeObject
|
||||||
|
|
||||||
, getObject
|
, getObject
|
||||||
, statObject
|
, statObject
|
||||||
@ -121,10 +122,18 @@ putObject bucket object src sizeMay =
|
|||||||
copyObject :: Bucket -> Object -> CopyPartSource -> Minio ()
|
copyObject :: Bucket -> Object -> CopyPartSource -> Minio ()
|
||||||
copyObject bucket object cps = void $ copyObjectInternal bucket object cps
|
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).
|
-- | Get an object from the object store as a resumable source (conduit).
|
||||||
getObject :: Bucket -> Object -> Minio (C.ResumableSource Minio ByteString)
|
getObject :: Bucket -> Object -> Minio (C.ResumableSource Minio ByteString)
|
||||||
getObject bucket object = snd <$> getObject' bucket object [] []
|
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
|
-- | Creates a new bucket in the object store. The Region can be
|
||||||
-- optionally specified. If not specified, it will use the region
|
-- optionally specified. If not specified, it will use the region
|
||||||
-- configured in ConnectInfo, which is by default, the US Standard
|
-- configured in ConnectInfo, which is by default, the US Standard
|
||||||
@ -135,11 +144,7 @@ makeBucket bucket regionMay= do
|
|||||||
putBucket bucket region
|
putBucket bucket region
|
||||||
modify (Map.insert bucket region)
|
modify (Map.insert bucket region)
|
||||||
|
|
||||||
-- | Get an object's metadata from the object store.
|
removeBucket :: Bucket -> Minio ()
|
||||||
statObject :: Bucket -> Object -> Minio ObjectInfo
|
|
||||||
statObject bucket object = headObject bucket object
|
|
||||||
|
|
||||||
removeBucket :: Bucket -> Minio()
|
|
||||||
removeBucket bucket = do
|
removeBucket bucket = do
|
||||||
deleteBucket bucket
|
deleteBucket bucket
|
||||||
modify (Map.delete bucket)
|
modify (Map.delete bucket)
|
||||||
|
|||||||
@ -160,7 +160,7 @@ liveServerUnitTests = testGroup "Unit tests against a live server"
|
|||||||
"Wrong file size of put file after getting"
|
"Wrong file size of put file after getting"
|
||||||
|
|
||||||
step $ "Cleanup actions"
|
step $ "Cleanup actions"
|
||||||
deleteObject bucket object
|
removeObject bucket object
|
||||||
|
|
||||||
-- putObject test (conduit source, no size specified)
|
-- putObject test (conduit source, no size specified)
|
||||||
let obj = "mpart"
|
let obj = "mpart"
|
||||||
@ -194,7 +194,7 @@ liveServerUnitTests = testGroup "Unit tests against a live server"
|
|||||||
"Wrong file size of put file after getting"
|
"Wrong file size of put file after getting"
|
||||||
|
|
||||||
step $ "Cleanup actions"
|
step $ "Cleanup actions"
|
||||||
deleteObject bucket obj
|
removeObject bucket obj
|
||||||
|
|
||||||
step "Prepare for putObjectInternal with large file as source."
|
step "Prepare for putObjectInternal with large file as source."
|
||||||
step "upload large object"
|
step "upload large object"
|
||||||
@ -202,7 +202,7 @@ liveServerUnitTests = testGroup "Unit tests against a live server"
|
|||||||
Just $ 1024*1024*100)
|
Just $ 1024*1024*100)
|
||||||
|
|
||||||
step "cleanup"
|
step "cleanup"
|
||||||
deleteObject bucket "big"
|
removeObject bucket "big"
|
||||||
|
|
||||||
|
|
||||||
, funTestWithBucket "Listing Test" $ \step bucket -> do
|
, funTestWithBucket "Listing Test" $ \step bucket -> do
|
||||||
@ -274,7 +274,7 @@ liveServerUnitTests = testGroup "Unit tests against a live server"
|
|||||||
|
|
||||||
step "Cleanup actions"
|
step "Cleanup actions"
|
||||||
forM_ expected $
|
forM_ expected $
|
||||||
\obj -> deleteObject bucket obj
|
\obj -> removeObject bucket obj
|
||||||
|
|
||||||
step "High-level listIncompleteUploads Test"
|
step "High-level listIncompleteUploads Test"
|
||||||
let object = "newmpupload"
|
let object = "newmpupload"
|
||||||
@ -336,8 +336,8 @@ liveServerUnitTests = testGroup "Unit tests against a live server"
|
|||||||
"Copied object did not match expected."
|
"Copied object did not match expected."
|
||||||
|
|
||||||
step "cleanup actions"
|
step "cleanup actions"
|
||||||
deleteObject bucket object
|
removeObject bucket object
|
||||||
deleteObject bucket objCopy
|
removeObject bucket objCopy
|
||||||
|
|
||||||
step "copyObjectPart basic tests"
|
step "copyObjectPart basic tests"
|
||||||
let srcObj = "XXX"
|
let srcObj = "XXX"
|
||||||
@ -370,8 +370,8 @@ liveServerUnitTests = testGroup "Unit tests against a live server"
|
|||||||
liftIO $ (s == mb15) @? "Size failed to match"
|
liftIO $ (s == mb15) @? "Size failed to match"
|
||||||
|
|
||||||
step $ "Cleanup actions"
|
step $ "Cleanup actions"
|
||||||
deleteObject bucket srcObj
|
removeObject bucket srcObj
|
||||||
deleteObject bucket copyObj
|
removeObject bucket copyObj
|
||||||
|
|
||||||
step "copyObject basic tests"
|
step "copyObject basic tests"
|
||||||
let srcs = ["XXX", "XXXL"]
|
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"
|
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 "
|
step "copyObject with offset test "
|
||||||
let src = "XXX"
|
let src = "XXX"
|
||||||
@ -412,5 +412,5 @@ liveServerUnitTests = testGroup "Unit tests against a live server"
|
|||||||
|
|
||||||
liftIO $ (cSize == 10 * 1024 * 1024) @? "Uploaded obj size mismatched!"
|
liftIO $ (cSize == 10 * 1024 * 1024) @? "Uploaded obj size mismatched!"
|
||||||
|
|
||||||
forM_ [src, copyObj] (deleteObject bucket)
|
forM_ [src, copyObj] (removeObject bucket)
|
||||||
]
|
]
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user