This repository was archived by the owner on May 23, 2019. It is now read-only.
forked from ArnoVanLumig/azurify
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBlobListParser.hs
40 lines (34 loc) · 2.07 KB
/
BlobListParser.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
{-# LANGUAGE Arrows, OverloadedStrings #-}
module BlobListParser where
import BlobDataTypes
import qualified Data.ByteString as B
import qualified Data.ByteString.Char8 as B8
import Text.XML.HXT.Core hiding (Blob)
parse xml = runX (readString [] xml >>> getBlobs >>> xmlBlob)
getBlobs :: (ArrowXml a) => a XmlTree XmlTree
getBlobs = deep (hasName "Blob")
xmlBlob :: (ArrowXml a) => a XmlTree Blob
xmlBlob = proc tag -> do
name <- (getText <<< getChildren <<< deep (hasName "Name")) -< tag
url <- (getText <<< getChildren <<< deep (hasName "Url")) -< tag
lastMod <- (getText <<< getChildren <<< deep (hasName "Last-Modified")) -< tag
etag <- (getText <<< getChildren <<< deep (hasName "Etag")) `orElse` (constA "") -< tag
contentLen <- (getText <<< getChildren <<< deep (hasName "Content-Length")) -< tag
contentType <- (getText <<< getChildren <<< deep (hasName "Content-Type")) `orElse` (constA "") -< tag
contentEnc <- (getText <<< getChildren <<< deep (hasName "Content-Encoding")) `orElse` (constA "") -< tag
contentLang <- (getText <<< getChildren <<< deep (hasName "Content-Language")) `orElse` (constA "") -< tag
contentMD5 <- (getText <<< getChildren <<< deep (hasName "Content-MD5")) `orElse` (constA "") -< tag
cacheControl <- (getText <<< getChildren <<< deep (hasName "Cache-Control")) `orElse` (constA "") -< tag
blobType <- (getText <<< getChildren <<< deep (hasName "BlobType")) -< tag
returnA -< Blob { blobName = B8.pack name
, blobUrl = B8.pack url
, blobLastModified = B8.pack lastMod
, blobETag = B8.pack etag
, blobContentLength = read contentLen
, blobContentType = B8.pack contentType
, blobContentEncoding = B8.pack contentEnc
, blobContentLanguage = B8.pack contentLang
, blobContentMD5 = B8.pack contentMD5
, blobCacheControl = B8.pack cacheControl
, blobType = if blobType == "PageBlob" then PageBlob else BlockBlob
}