diff src/luan/modules/IoLuan.java @ 1083:e7fb974e0c26

add Io checksum and use it for push
author Franklin Schmidt <fschmidt@gmail.com>
date Mon, 21 Nov 2016 22:48:43 -0700
parents 9c13a15a4002
children 27bf094f0ae3
line wrap: on
line diff
--- a/src/luan/modules/IoLuan.java	Tue Nov 15 19:19:19 2016 -0700
+++ b/src/luan/modules/IoLuan.java	Mon Nov 21 22:48:43 2016 -0700
@@ -225,6 +225,17 @@
 			}
 		}
 
+		public long checksum() throws IOException, LuanException {
+			long cs = 0;
+			InputStream in = new BufferedInputStream(inputStream());
+			int c;
+			while( (c=in.read()) != -1 ) {
+				cs = 31 * cs + c;
+			}
+			in.close();
+			return cs;
+		}
+
 		public LuanTable table() {
 			LuanTable tbl = new LuanTable();
 			try {
@@ -250,6 +261,9 @@
 				tbl.rawPut( "exists", new LuanJavaFunction(
 					LuanIn.class.getMethod( "exists" ), this
 				) );
+				tbl.rawPut( "checksum", new LuanJavaFunction(
+					LuanIn.class.getMethod( "checksum" ), this
+				) );
 			} catch(NoSuchMethodException e) {
 				throw new RuntimeException(e);
 			}