diff --git a/cartographer/common/port.h b/cartographer/common/port.h
index eec8469..96881ad 100644
--- a/cartographer/common/port.h
+++ b/cartographer/common/port.h
@@ -17,12 +17,14 @@
 #ifndef CARTOGRAPHER_COMMON_PORT_H_
 #define CARTOGRAPHER_COMMON_PORT_H_
 
-#include <boost/iostreams/device/back_inserter.hpp>
-#include <boost/iostreams/filter/gzip.hpp>
-#include <boost/iostreams/filtering_stream.hpp>
 #include <cinttypes>
+#include <cstring>
 #include <cmath>
 #include <string>
+#include <stdexcept>
+#include <functional>
+
+#include <zlib.h>
 
 namespace cartographer {
 
@@ -47,22 +49,54 @@ inline int64 RoundToInt64(const double x) { return std::lround(x); }
 
 inline void FastGzipString(const std::string& uncompressed,
                            std::string* compressed) {
-  boost::iostreams::filtering_ostream out;
-  out.push(
-      boost::iostreams::gzip_compressor(boost::iostreams::zlib::best_speed));
-  out.push(boost::iostreams::back_inserter(*compressed));
-  boost::iostreams::write(out,
-                          reinterpret_cast<const char*>(uncompressed.data()),
-                          uncompressed.size());
+    z_stream zs;
+    memset(&zs, 0, sizeof(zs));
+
+    if (deflateInit(&zs, Z_BEST_SPEED) != Z_OK)
+        throw std::runtime_error("deflateInit failed while compressing.");
+
+    zs.next_in = reinterpret_cast<Bytef*>(const_cast<char*>(uncompressed.data()));
+    zs.avail_in = static_cast<uInt>(uncompressed.size());
+
+    int ret;
+    char buffer[4096];
+
+    do {
+        zs.next_out = reinterpret_cast<Bytef*>(buffer);
+        zs.avail_out = sizeof(buffer);
+
+        ret = deflate(&zs, Z_FINISH);
+
+        compressed->append(buffer, sizeof(buffer) - zs.avail_out);
+    } while (zs.avail_out == 0);
+
+    deflateEnd(&zs);
 }
 
 inline void FastGunzipString(const std::string& compressed,
                              std::string* decompressed) {
-  boost::iostreams::filtering_ostream out;
-  out.push(boost::iostreams::gzip_decompressor());
-  out.push(boost::iostreams::back_inserter(*decompressed));
-  boost::iostreams::write(out, reinterpret_cast<const char*>(compressed.data()),
-                          compressed.size());
+    z_stream zs;
+    memset(&zs, 0, sizeof(zs));
+
+    if (inflateInit(&zs) != Z_OK)
+        throw std::runtime_error("inflateInit failed while decompressing.");
+
+    zs.next_in = reinterpret_cast<Bytef*>(const_cast<char*>(compressed.data()));
+    zs.avail_in = static_cast<uInt>(compressed.size());
+
+    int ret;
+    char buffer[4096];
+
+    do {
+        zs.next_out = reinterpret_cast<Bytef*>(buffer);
+        zs.avail_out = sizeof(buffer);
+
+        ret = inflate(&zs, Z_NO_FLUSH);
+
+        decompressed->append(buffer, sizeof(buffer) - zs.avail_out);
+    } while (zs.avail_out == 0);
+
+    inflateEnd(&zs);
 }
 
 }  // namespace common
