3232use GuzzleHttp \Psr7 ;
3333use GuzzleHttp \Psr7 \Utils ;
3434use OC \Files \Stream \SeekableHttpStream ;
35- use OCP \Files \ExpectedFileSizeException ;
3635use Psr \Http \Message \StreamInterface ;
3736
3837trait S3ObjectTrait {
@@ -53,8 +52,8 @@ abstract protected function getCertificateBundlePath(): ?string;
5352 * @throws \Exception when something goes wrong, message will be logged
5453 * @since 7.0.0
5554 */
56- public function readObject ($ urn, int $ expectedFileSize = - 1 ) {
57- return SeekableHttpStream::open (function ($ range ) use ($ urn, $ expectedFileSize ) {
55+ public function readObject ($ urn ) {
56+ return SeekableHttpStream::open (function ($ range ) use ($ urn ) {
5857 $ command = $ this ->getConnection ()->getCommand ('GetObject ' , [
5958 'Bucket ' => $ this ->bucket ,
6059 'Key ' => $ urn ,
@@ -86,50 +85,11 @@ public function readObject($urn, int $expectedFileSize = -1) {
8685 }
8786
8887 $ context = stream_context_create ($ opts );
89- $ res = fopen ($ request ->getUri (), 'r ' , false , $ context );
90-
91- if (substr ($ range , 0 , 2 ) !== '0- ' ) {
92- return $ res ;
93- }
94-
95- $ actualContentLength = $ this ->extractDataContentLength ($ res );
96- if ($ actualContentLength > -1
97- && $ expectedFileSize > -1
98- && $ actualContentLength !== $ expectedFileSize ) {
99- throw new ExpectedFileSizeException (
100- 'cached file size conflict ' ,
101- $ actualContentLength
102- );
103- }
104-
105- return $ res ;
88+ return fopen ($ request ->getUri (), 'r ' , false , $ context );
10689 });
10790 }
10891
10992
110- /**
111- * will return -1 if $res is a bool (not a resource)
112- *
113- * @param resource $res
114- *
115- * @return int
116- */
117- private function extractDataContentLength ($ res ): int {
118- if (is_bool ($ res )) {
119- return -1 ;
120- }
121-
122- $ data = stream_get_meta_data ($ res )['wrapper_data ' ];
123- foreach ($ data as $ entry ) {
124- if (strtolower (substr ($ entry , 0 , 16 )) === 'content-length: ' ) {
125- return (int )substr ($ entry , 16 );
126- }
127- }
128-
129- return -1 ;
130- }
131-
132-
13393 /**
13494 * Single object put helper
13595 *
0 commit comments