Пример #1
0
        public TextWriter GetWriter(Uri uri)
        {
            string local_path = LookupPathRaw(uri);

            // LookupPathRaw returns local path, if NOT self_cached
            if (local_path == SELF_CACHE_TAG)
            {
                throw new ArgumentException("uri", String.Format("Cannot return TextCache writer for self-cached file {0}", uri));
            }

            // If there is no path, create new prospective path, by called Guid.NewGuid()
            if (local_path == null || local_path == BLOB_TAG)
            {
                string guid = Guid.NewGuid().ToString();
                local_path = Path.Combine(guid.Substring(0, 2), guid.Substring(2));
            }

            // Return TextCacheWriteStream (Uri, path, handler)
            Stream stream;

            stream = new TextCacheWriteStream(Path.Combine(text_cache_dir, local_path),
                                              world_readable,
                                              delegate(byte[] buffer)
            {
                CachedDataWriteFinished(uri, local_path, buffer);
            });

            // But after wrapping it with compression
            stream = new GZipOutputStream(stream);

            StreamWriter writer;

            writer = new StreamWriter(new BufferedStream(stream));
            return(writer);
        }
Пример #2
0
		public TextWriter GetWriter (Uri uri)
		{
			string local_path = LookupPathRaw (uri);

			// LookupPathRaw returns local path, if NOT self_cached
			if (local_path == SELF_CACHE_TAG)
				throw new ArgumentException ("uri", String.Format ("Cannot return TextCache writer for self-cached file {0}", uri));

			// If there is no path, create new prospective path, by called Guid.NewGuid()
			if (local_path == null || local_path == BLOB_TAG) {
				string guid = Guid.NewGuid ().ToString ();
				local_path = Path.Combine (guid.Substring (0, 2), guid.Substring (2));
			}

			// Return TextCacheWriteStream (Uri, path, handler)
			Stream stream;
			stream = new TextCacheWriteStream (Path.Combine (text_cache_dir, local_path),
							   world_readable,
							   delegate (byte[] buffer)
							   {
								CachedDataWriteFinished (uri, local_path, buffer);
							   });

			// But after wrapping it with compression
			stream = new GZipOutputStream (stream);

			StreamWriter writer;
			writer = new StreamWriter (new BufferedStream (stream));
			return writer;
		}