comparison Core/HttpServer/FilesystemHttpSender.cpp @ 1523:c388502a066d

testing FilesystemHttpSender
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 11 Aug 2015 16:09:00 +0200
parents f938f7779bcb
children f9b0169eb6bb
comparison
equal deleted inserted replaced
1522:f938f7779bcb 1523:c388502a066d
60 size_ = file_.tellg(); 60 size_ = file_.tellg();
61 file_.seekg(0, file_.beg); 61 file_.seekg(0, file_.beg);
62 } 62 }
63 63
64 64
65 HttpCompression FilesystemHttpSender::GetHttpCompression(bool gzipAllowed, 65 HttpCompression FilesystemHttpSender::SetupHttpCompression(bool gzipAllowed,
66 bool deflateAllowed) 66 bool deflateAllowed)
67 { 67 {
68 switch (sourceCompression_) 68 switch (sourceCompression_)
69 { 69 {
70 case CompressionType_None: 70 case CompressionType_None:
71 { 71 {
84 throw OrthancException(ErrorCode_CorruptedFile); 84 throw OrthancException(ErrorCode_CorruptedFile);
85 } 85 }
86 86
87 if (deflateAllowed) 87 if (deflateAllowed)
88 { 88 {
89 file_.seekg(sizeof(uint64_t), file_.end); 89 file_.seekg(sizeof(uint64_t), file_.beg);
90 size_ -= sizeof(uint64_t);
90 return HttpCompression_Deflate; 91 return HttpCompression_Deflate;
91 } 92 }
92 else 93 else
93 { 94 {
94 uncompressed_.reset(new BufferHttpSender); 95 uncompressed_.reset(new BufferHttpSender);
98 std::string compressed; 99 std::string compressed;
99 compressed.resize(size_); 100 compressed.resize(size_);
100 101
101 file_.read(&compressed[0], size_); 102 file_.read(&compressed[0], size_);
102 if ((file_.flags() & std::istream::failbit) || 103 if ((file_.flags() & std::istream::failbit) ||
103 !(file_.flags() & std::istream::eofbit)) 104 !(file_.flags() & std::istream::eofbit) ||
105 file_.gcount() < 0 ||
106 static_cast<uint64_t>(file_.gcount()) != size_)
104 { 107 {
105 throw OrthancException(ErrorCode_CorruptedFile); 108 throw OrthancException(ErrorCode_CorruptedFile);
106 } 109 }
107 110
108 ZlibCompressor compressor; 111 ZlibCompressor compressor;
109 IBufferCompressor::Uncompress(uncompressed_->GetBuffer(), compressor, compressed); 112 IBufferCompressor::Uncompress(uncompressed_->GetBuffer(), compressor, compressed);
113
110 return HttpCompression_None; 114 return HttpCompression_None;
111 } 115 }
112 116
113 break; 117 break;
114 } 118 }
115 119
116 default: 120 default:
117 throw OrthancException(ErrorCode_NotImplemented); 121 throw OrthancException(ErrorCode_NotImplemented);
122 }
123 }
124
125
126 uint64_t FilesystemHttpSender::GetContentLength()
127 {
128 if (uncompressed_.get() != NULL)
129 {
130 return uncompressed_->GetContentLength();
131 }
132 else
133 {
134 return size_;
118 } 135 }
119 } 136 }
120 137
121 138
122 bool FilesystemHttpSender::ReadNextChunk() 139 bool FilesystemHttpSender::ReadNextChunk()