hstratus-drive — access to iCloud Drive
hstratus-drive browses, downloads, and mutates files in iCloud Drive using an
authenticated session from hstratus-auth.
The library provides access to the main CloudDocs tree: fetching the root
folder, listing folder contents, downloading files, and mutating the tree
(create, rename, delete, upload).
Disclaimer — use at your own risk
- This library is unofficial and not supported by Apple.
- The iCloud Drive API it uses is undocumented and may change without notice.
Usage
After a successful login with hstratus-auth, construct a DriveApi value and
use it to browse, download, or mutate files.
Browsing
import Network.HStratus.Http (mkApi, login, AuthState (..))
import Network.HStratus.Http.Endpoints (Realm (..))
import Network.HStratus.Drive
example :: IO ()
example = do
api <- mkApi Usual
result <- login api
case result of
Authenticated sess ad -> do
da <- mkDriveApi ad sess api
root <- driveRoot da
nodes <- listFolder da (fnId root)
mapM_ print nodes
_ -> putStrLn "Unexpected result"
Downloading
downloadExample :: DriveApi -> FileData -> IO ()
downloadExample da fd = do
bytes <- downloadFile da fd
-- bytes :: Data.ByteString.Lazy.ByteString
print (Data.ByteString.Lazy.length bytes)
Mutating
mutationExample :: DriveApi -> FolderData -> IO ()
mutationExample da folder = do
createFolder da (fnId folder) "New Folder"
-- renameNode, deleteNode, and uploadFile follow the same pattern
CLI usage
A command-line interface using this behaviour is provided by the hstratus
package. Use hstratus drive ls to list Drive contents and
hstratus drive cp to download files.
Apple and the Apple logo are trademarks of Apple Inc., registered in the U.S. and other countries and regions.
iCloud is a service mark of Apple Inc., registered in the U.S. and other countries and regions.