From 73a88143d56ad51a18fef3528c786461992ace20 Mon Sep 17 00:00:00 2001 From: Aditya Manthramurthy Date: Fri, 6 Jan 2017 02:57:26 +0530 Subject: [PATCH] GetObject s3api and fGetObject api - Also updates to lts 6.27 (to be able to use sinkFileCautious) --- app/Main.hs | 2 ++ minio-hs.cabal | 3 +++ src/Network/Minio.hs | 15 +++++++++++++++ src/Network/Minio/API.hs | 6 ++++-- src/Network/Minio/S3API.hs | 11 ++++++++++- stack.yaml | 20 ++++++++++---------- 6 files changed, 44 insertions(+), 13 deletions(-) diff --git a/app/Main.hs b/app/Main.hs index 417efbf..d06ae7c 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -31,5 +31,7 @@ main = do res <- getLocation "test1" print res + fGetObject "test1" "passwd" "/tmp/passwd" + print "After runResourceT" print t diff --git a/minio-hs.cabal b/minio-hs.cabal index fe587ce..dd25d43 100644 --- a/minio-hs.cabal +++ b/minio-hs.cabal @@ -31,9 +31,12 @@ library , bytestring , case-insensitive , conduit + , conduit-combinators + , conduit-extra , containers , cryptonite , errors + , filepath , http-client , http-conduit , http-types diff --git a/src/Network/Minio.hs b/src/Network/Minio.hs index 6ba2185..7cc1065 100644 --- a/src/Network/Minio.hs +++ b/src/Network/Minio.hs @@ -1,5 +1,6 @@ module Network.Minio ( module Exports + , fGetObject ) where {- @@ -19,3 +20,17 @@ import Network.Minio.Data as , connect , ConnectInfo(..) ) + +import System.FilePath +import qualified Data.Conduit as C +import qualified Data.Conduit.Binary as CB + +import Lib.Prelude + +import Network.Minio.Data +import Network.Minio.S3API + +fGetObject :: Bucket -> Object -> FilePath -> Minio () +fGetObject bucket object fp = do + (_, src) <- getObject bucket object [] [] + src C.$$+- CB.sinkFileCautious fp diff --git a/src/Network/Minio/API.hs b/src/Network/Minio/API.hs index 1391423..76fd898 100644 --- a/src/Network/Minio/API.hs +++ b/src/Network/Minio/API.hs @@ -5,6 +5,7 @@ module Network.Minio.API , RequestInfo(..) , runMinio , executeRequest + , mkStreamRequest , requestInfo ) where @@ -61,8 +62,9 @@ executeRequest ri = do NC.httpLbs req mgr -mkSRequest :: RequestInfo -> Minio (Response (C.ResumableSource Minio ByteString)) -mkSRequest ri = do +mkStreamRequest :: RequestInfo + -> Minio (Response (C.ResumableSource Minio ByteString)) +mkStreamRequest ri = do let PayloadSingle pload = payload ri phash = hashSHA256 pload newRI = ri { diff --git a/src/Network/Minio/S3API.hs b/src/Network/Minio/S3API.hs index 456e8f8..bbe7388 100644 --- a/src/Network/Minio/S3API.hs +++ b/src/Network/Minio/S3API.hs @@ -1,10 +1,12 @@ module Network.Minio.S3API ( getService , getLocation + , getObject ) where import qualified Network.HTTP.Types as HT import qualified Network.HTTP.Conduit as NC +import qualified Data.Conduit as C import Lib.Prelude @@ -27,4 +29,11 @@ getLocation bucket = do (PayloadSingle "") parseLocation $ NC.responseBody resp --- getObject :: +getObject :: Bucket -> Object -> HT.Query -> [HT.Header] + -> Minio ([HT.Header], C.ResumableSource Minio ByteString) +getObject bucket object queryParams headers = do + resp <- mkStreamRequest reqInfo + return $ (NC.responseHeaders resp, NC.responseBody resp) + where + reqInfo = requestInfo HT.methodGet (Just bucket) (Just object) + queryParams headers (PayloadSingle "") diff --git a/stack.yaml b/stack.yaml index 93d2721..3e69219 100644 --- a/stack.yaml +++ b/stack.yaml @@ -1,5 +1,5 @@ # This file was automatically generated by 'stack init' -# +# # Some commonly used options have been documented as comments in this file. # For advanced use and comprehensive documentation of the format, please see: # http://docs.haskellstack.org/en/stable/yaml_configuration/ @@ -7,7 +7,7 @@ # Resolver to choose a 'specific' stackage snapshot or a compiler version. # A snapshot resolver dictates the compiler version and the set of packages # to be used for project dependencies. For example: -# +# # resolver: lts-3.5 # resolver: nightly-2015-09-21 # resolver: ghc-7.10.2 @@ -15,11 +15,11 @@ # resolver: # name: custom-snapshot # location: "./custom-snapshot.yaml" -resolver: lts-6.15 +resolver: lts-6.27 # User packages to be built. # Various formats can be used as shown in the example below. -# +# # packages: # - some-directory # - https://example.com/foo/bar/baz-0.0.2.tar.gz @@ -31,7 +31,7 @@ resolver: lts-6.15 # subdirs: # - auto-update # - wai -# +# # A package marked 'extra-dep: true' will only be built if demanded by a # non-dependency (i.e. a user package), and its test suites and benchmarks # will not be run. This is useful for tweaking upstream packages. @@ -49,18 +49,18 @@ extra-package-dbs: [] # Control whether we use the GHC we find on the path # system-ghc: true -# +# # Require a specific version of stack, using version ranges # require-stack-version: -any # Default # require-stack-version: ">=1.1" -# +# # Override the architecture used by stack, especially useful on Windows # arch: i386 # arch: x86_64 -# +# # Extra directories used by stack for building # extra-include-dirs: [/path/to/dir] # extra-lib-dirs: [/path/to/dir] -# +# # Allow a newer minor version of GHC than the snapshot specifies -# compiler-check: newer-minor \ No newline at end of file +# compiler-check: newer-minor