diff --git a/LICENSE b/LICENSE
new file mode 100644
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,21 @@
+The MIT License
+
+Copyright (c) 2011 Nicholas Ingolia
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
diff --git a/Setup.hs b/Setup.hs
new file mode 100644
--- /dev/null
+++ b/Setup.hs
@@ -0,0 +1,2 @@
+import Distribution.Simple
+main = defaultMain
diff --git a/samtools-enumerator.cabal b/samtools-enumerator.cabal
new file mode 100644
--- /dev/null
+++ b/samtools-enumerator.cabal
@@ -0,0 +1,18 @@
+Name:                samtools-enumerator
+Version:             0.1
+Synopsis:            Enumerator interface to SamTools library
+Description:         Enumerator interface to SamTools library
+License:             MIT
+License-file:        LICENSE
+Author:              Nicholas Ingolia
+Maintainer:          nick@ingolia.org
+Category:            Bio
+
+Build-type:          Simple
+Cabal-version:       >=1.4
+
+Library
+  Exposed-modules:     Bio.SamTools.Enumerator
+  Build-depends:       base >= 4.3 && < 5, bytestring, haskell98, transformers, enumerator >= 0.4.7 && < 0.5, samtools >= 0.1.1 && < 0.2
+  Hs-Source-Dirs:      src
+
diff --git a/src/Bio/SamTools/Enumerator.hs b/src/Bio/SamTools/Enumerator.hs
new file mode 100644
--- /dev/null
+++ b/src/Bio/SamTools/Enumerator.hs
@@ -0,0 +1,76 @@
+module Bio.SamTools.Enumerator 
+       (
+       -- | BAM/SAM enumeration
+         enumInHandle
+       , enumTam, enumTamWithIndex, enumBam
+       -- | Indexed BAM region enumeration
+       , enumQuery, enumIndexRegion, enumBamRegion
+       -- | BAM/SAM iteration
+       , iterHandle
+       )
+       where
+
+import Control.Exception (bracket, bracket_, finally)
+import Control.Monad
+import Control.Monad.IO.Class
+import qualified Data.ByteString.Char8 as BS
+import Data.Int (Int64)
+import Data.List
+import Data.Maybe
+
+import qualified Bio.SamTools.Bam as Bam
+import qualified Bio.SamTools.BamIndex as BamIndex
+import qualified Data.Enumerator as E
+
+-- | Enumerate over the contents of a BAM/SAM alignment input handle
+enumInHandle :: (MonadIO m) => Bam.InHandle -> E.Enumerator Bam.Bam1 m a
+enumInHandle inh = loop
+  where loop (E.Continue k) = (liftIO $ Bam.get1 inh) >>= maybe eof next
+          where eof = E.returnI (E.Continue k)
+                next b = k (E.Chunks [b]) E.>>== loop
+        loop step = E.returnI step
+
+-- | Enumerate over the contents of a TAM (tab-delimited text) alignment file
+enumTam :: FilePath -> E.Enumerator Bam.Bam1 IO a
+enumTam inname step = E.Iteratee $ liftIO $ bracket (Bam.openTamInFile inname) Bam.closeInHandle $ \h ->
+  E.runIteratee $ enumInHandle h step
+
+-- | Enumerate over the contents of a TAM file with a separate target sequence index
+enumTamWithIndex :: FilePath -> FilePath -> E.Enumerator Bam.Bam1 IO a
+enumTamWithIndex inname idxname step
+  = E.Iteratee $ liftIO $ bracket (Bam.openTamInFileWithIndex inname idxname) Bam.closeInHandle $ \h ->
+  E.runIteratee $ enumInHandle h step
+
+-- | Enumerate over the contents of a BAM (binary) alignment file
+enumBam :: FilePath -> E.Enumerator Bam.Bam1 IO a
+enumBam inname step = E.Iteratee $ liftIO $ bracket (Bam.openBamInFile inname) Bam.closeInHandle $ \h ->
+  E.runIteratee $ enumInHandle h step
+
+-- | Enumerate over the results of a query into a sorted, indexed BAM file
+enumQuery :: BamIndex.Query -> E.Enumerator Bam.Bam1 IO a
+enumQuery q = loop
+  where loop (E.Continue k) = (liftIO $ BamIndex.next q) >>= maybe end next
+            where end = E.returnI (E.Continue k)
+                  next b = k (E.Chunks [b]) E.>>== loop
+        loop step = E.returnI step
+        
+-- | Enumerate over the reads in a region from an indexed BAM file input handle
+enumIndexRegion :: BamIndex.IdxHandle -> Int -> (Int64, Int64) -> E.Enumerator Bam.Bam1 IO a
+enumIndexRegion h tid bnds step = E.Iteratee $ do 
+  q <- liftIO $ BamIndex.query h tid bnds 
+  E.runIteratee $ enumQuery q step
+
+-- | Enumerate over the reads in a region from a sorted, indexed BAM file
+enumBamRegion :: FilePath -> BS.ByteString -> (Int64, Int64) -> E.Enumerator Bam.Bam1 IO a
+enumBamRegion inname seqname bnds step = E.Iteratee $ liftIO $ bracket (BamIndex.open inname) (BamIndex.close) $ \h -> do
+  tid <- lookupTid $ BamIndex.idxHeader h
+  E.runIteratee $ enumIndexRegion h tid bnds step
+    where lookupTid = maybe noTid return . findIndex ((== seqname) . Bam.name) . Bam.targetSeqList
+          noTid = ioError . userError $ "Target " ++ show seqname ++ " not found in " ++ show inname
+          
+iterHandle :: Bam.OutHandle -> E.Iteratee Bam.Bam1 IO ()
+iterHandle h = E.continue step
+  where step E.EOF = E.yield () E.EOF
+        step (E.Chunks []) = E.continue step
+        step (E.Chunks bs) = do liftIO $ forM_ bs $ Bam.put1 h
+                                E.continue step
