 
      req.pipe file
 
+# Automatically derives and returns the name of the destination DZI.
+# TODO: Find some way to report progress here.
+createDZI = (src, _) ->
+    dir = Path.dirname src
+    ext = Path.extname src
+    base = Path.basename src, ext
+    dest = Path.join dir, "#{base}.dzi"
+
+    DeepZoomImage.create _, src, dest
+
+    dest
+
 
 ## MAIN:
 


config = require '../config'
crypto = require 'crypto'
FS = require 'fs-extra'
OS = require 'os'
Path = require 'path'

        dir = makeTempDir _

        # Download the content to a file (within our temp dir) named by the ID:
        file = Path.join dir, content.id
        echo 'Downloading content to temp dir... id=%j, file=%j', id, file
        downloadFile content.url, file, _

        echo 'Generating DZI for content... id=%j', id
        dzi = createDZI file, _

        echo 'Parsing the generated DZI... id=%j', id
        dzi = DZIParser.parse dzi, _

        # TODO: Upload!

        # erro 'Success! Marking content as ready... id=%j', id
        # content.markReady dzi, _
