Ori.livneh has submitted this change and it was merged.

Change subject: Backport of D2486378: Implement compress.bzip2:// stream wrapper
......................................................................


Backport of D2486378: Implement compress.bzip2:// stream wrapper

Bug: T113932
Change-Id: I0f064cb92d96d32a0409825328bc9865246bacbe
---
A debian/patches/D2486378-compress_bzip2.patch
M debian/patches/series
2 files changed, 167 insertions(+), 0 deletions(-)

Approvals:
  Ori.livneh: Verified; Looks good to me, approved



diff --git a/debian/patches/D2486378-compress_bzip2.patch 
b/debian/patches/D2486378-compress_bzip2.patch
new file mode 100644
index 0000000..8a33b54
--- /dev/null
+++ b/debian/patches/D2486378-compress_bzip2.patch
@@ -0,0 +1,166 @@
+From 46d04cfdb6b5987946f19ed6c65cee676e27b254 Mon Sep 17 00:00:00 2001
+From: Sara Golemon <[email protected]>
+Date: Tue, 29 Sep 2015 14:28:41 -0700
+Subject: [PATCH] Implement compress.bzip2:// stream wrapper
+
+Summary: Wraper BZ2File implementation with an opener.
+
+Closes https://github.com/facebook/hhvm/issues/6314
+
+Reviewed By: @paulbiss, @fredemmott
+
+Differential Revision: D2486378
+---
+ hphp/runtime/ext/bz2/ext_bz2.cpp            | 45 +++++++++++++++++++++++++++++
+ hphp/test/slow/ext_bzip2/wrapper.php        | 43 +++++++++++++++++++++++++++
+ hphp/test/slow/ext_bzip2/wrapper.php.expect | 21 ++++++++++++++
+ 3 files changed, 109 insertions(+)
+ create mode 100644 hphp/test/slow/ext_bzip2/wrapper.php
+ create mode 100644 hphp/test/slow/ext_bzip2/wrapper.php.expect
+
+diff --git a/hphp/runtime/ext/bz2/ext_bz2.cpp 
b/hphp/runtime/ext/bz2/ext_bz2.cpp
+index 174d109..bea8d5a 100644
+--- a/hphp/runtime/ext/bz2/ext_bz2.cpp
++++ b/hphp/runtime/ext/bz2/ext_bz2.cpp
+@@ -17,6 +17,8 @@
+ 
+ #include "hphp/runtime/ext/bz2/bz2-file.h"
+ #include "hphp/runtime/ext/std/ext_std_file.h"
++#include "hphp/runtime/base/stream-wrapper.h"
++#include "hphp/runtime/base/file-stream-wrapper.h"
+ #include "hphp/util/alloc.h"
+ #include <folly/String.h>
+ 
+@@ -31,6 +33,44 @@
+ 
+ namespace HPHP {
+ 
///////////////////////////////////////////////////////////////////////////////
++// compress.zlib:// stream wrapper
++
++namespace {
++static struct BZ2StreamWrapper : Stream::Wrapper {
++  virtual req::ptr<File> open(const String& filename,
++                              const String& mode,
++                              int options,
++                              const req::ptr<StreamContext>& context) {
++    static const char cz[] = "compress.bzip2://";
++
++    if (strncmp(filename.c_str(), cz, sizeof(cz) - 1)) {
++      assert(false);
++      return nullptr;
++    }
++
++    String fname(filename.substr(sizeof(cz) - 1));
++    String translated;
++    if (fname.find("://") == -1) {
++      translated = File::TranslatePath(fname);
++      if (auto file = FileStreamWrapper::openFromCache(translated, mode)) {
++        file->unzip();
++        return file;
++      }
++    } else {
++      translated = fname;
++    }
++
++    auto file = req::make<BZ2File>();
++    if (!file->open(translated, mode)) {
++      raise_warning("%s", file->getLastError().c_str());
++      return nullptr;
++    }
++    return file;
++  }
++} s_bzip2_stream_wrapper;
++} // nil namespace
++
++///////////////////////////////////////////////////////////////////////////////
+ 
+ bool HHVM_FUNCTION(bzclose, const Resource& bz) {
+   return HHVM_FN(fclose)(bz);
+@@ -204,6 +244,11 @@ Variant HHVM_FUNCTION(bzdecompress, const String& source, 
int small /* = 0 */) {
+ class bz2Extension final : public Extension {
+  public:
+   bz2Extension() : Extension("bz2") {}
++
++  void moduleLoad(const IniSetting::Map& ini, Hdf hdf) override {
++    s_bzip2_stream_wrapper.registerAs("compress.bzip2");
++  }
++
+   void moduleInit() override {
+     HHVM_FE(bzclose);
+     HHVM_FE(bzread);
+diff --git a/hphp/test/slow/ext_bzip2/wrapper.php 
b/hphp/test/slow/ext_bzip2/wrapper.php
+new file mode 100644
+index 0000000..d7d6463
+--- /dev/null
++++ b/hphp/test/slow/ext_bzip2/wrapper.php
+@@ -0,0 +1,43 @@
++<?php
++
++$loremIpsum = <<<LOREM_IPSUM
++Lorem ipsum dolor sit amet,
++consectetur adipiscing elit,
++sed do eiusmod tempor incididunt
++ut labore et dolore magna aliqua.
++
++Ut enim ad minim veniam,
++quis nostrud exercitation ullamco laboris
++nisi ut aliquip ex ea commodo consequat.
++
++Duis aute irure dolor in reprehenderit
++in voluptate velit esse cillum dolore
++eu fugiat nulla pariatur.
++
++Excepteur sint occaecat cupidatat non proident,
++sunt in culpa qui officia deserunt mollit anim id est laborum.
++
++LOREM_IPSUM;
++
++$fn = tempnam(sys_get_temp_dir(), "hhvm-bz2-");
++$fp = file_put_contents("compress.bzip2://$fn", $loremIpsum);
++echo "Written: ";
++var_dump(file_exists($fn));
++echo "Readable: ";
++var_dump(is_readable($fn));
++
++// bz2 should be able to compress it by at least 25%
++$compressedSize = filesize($fn);
++echo "Contains data: ";
++var_dump($compressedSize > 0);
++echo "Compressed from original: ";
++var_dump($compressedSize < (strlen($loremIpsum) * 3/4));
++
++$readContents = file_get_contents("compress.bzip2://$fn");
++echo 'Match: ';
++var_dump($loremIpsum === $readContents);
++
++echo "----- Contents -----\n";
++readfile("compress.bzip2://$fn");
++
++unlink($fn);
+diff --git a/hphp/test/slow/ext_bzip2/wrapper.php.expect 
b/hphp/test/slow/ext_bzip2/wrapper.php.expect
+new file mode 100644
+index 0000000..6016048
+--- /dev/null
++++ b/hphp/test/slow/ext_bzip2/wrapper.php.expect
+@@ -0,0 +1,21 @@
++Written: bool(true)
++Readable: bool(true)
++Contains data: bool(true)
++Compressed from original: bool(true)
++Match: bool(true)
++----- Contents -----
++Lorem ipsum dolor sit amet,
++consectetur adipiscing elit,
++sed do eiusmod tempor incididunt
++ut labore et dolore magna aliqua.
++
++Ut enim ad minim veniam,
++quis nostrud exercitation ullamco laboris
++nisi ut aliquip ex ea commodo consequat.
++
++Duis aute irure dolor in reprehenderit
++in voluptate velit esse cillum dolore
++eu fugiat nulla pariatur.
++
++Excepteur sint occaecat cupidatat non proident,
++sunt in culpa qui officia deserunt mollit anim id est laborum.
diff --git a/debian/patches/series b/debian/patches/series
index 64adb14..dc008b6 100644
--- a/debian/patches/series
+++ b/debian/patches/series
@@ -15,4 +15,5 @@
 D45165-unserialize_ex.patch
 D44265-filter_var_array.patch
 D37899-ext_reflection.patch
+D2486378-compress_bzip2.patch
 

-- 
To view, visit https://gerrit.wikimedia.org/r/242773
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I0f064cb92d96d32a0409825328bc9865246bacbe
Gerrit-PatchSet: 2
Gerrit-Project: operations/debs/hhvm
Gerrit-Branch: master
Gerrit-Owner: BryanDavis <[email protected]>
Gerrit-Reviewer: Ori.livneh <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to