From 46a90c56004d109b7b7a4ff59e9e6eda85e4b4b9 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Johan=20Sch=C3=B6n?= <js@opera.com>
Date: Mon, 14 Feb 2000 22:26:18 +0100
Subject: [PATCH] Added downloaded_bytes() and total_bytes().

Rev: lib/modules/Protocols.pmod/HTTP.pmod/Query.pike:1.12
---
 .../Protocols.pmod/HTTP.pmod/Query.pike       | 24 +++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/lib/modules/Protocols.pmod/HTTP.pmod/Query.pike b/lib/modules/Protocols.pmod/HTTP.pmod/Query.pike
index 51193c9e59..1db1046fa4 100644
--- a/lib/modules/Protocols.pmod/HTTP.pmod/Query.pike
+++ b/lib/modules/Protocols.pmod/HTTP.pmod/Query.pike
@@ -84,6 +84,13 @@
 **! method string data()
 **!	Gives back the data as a string.
 **!
+**! metohd int downloaded_bytes()
+**!	Gives back the number of downloaded bytes.
+**!
+**! method int total_bytes()
+**!     Gives back the size of a file if a content-length header is present
+**!     and parsed at the time of evaluation. Otherwise returns -1.
+**!
 **! object(pseudofile) file()
 **! object(pseudofile) file(mapping newheaders,void|mapping removeheaders)
 **! object(pseudofile) datafile();
@@ -535,6 +542,23 @@ string data()
    return buf[datapos..];
 }
 
+int downloaded_bytes()
+{
+  if(datapos)
+    return sizeof(buf)-datapos;
+  else
+    return 0;
+}
+
+int total_bytes()
+{
+   int len=(int)headers["content-length"];
+   if(zero_type(len))
+     return -1;
+   else
+     return len;
+}
+
 array|mapping|string cast(string to)
 {
    switch (to)
-- 
GitLab