예제 #1
0
        /**
         * Replace GDocs with .url files
         */
        private void PlaceUrlFiles(Metadata metadata)
        {
            if (metadata.gdocs_link != null && !metadata.is_dir)
            {
                metadata.path = metadata.path + ".url";
                metadata.bytes = 24 + (ulong)metadata.gdocs_link.Length;
                metadataCache[stripLeadingSlash(metadata.path)] = metadata;
            }

            if (metadata.content != null)
            {
                foreach (var item in metadata.content)
                {
                    PlaceUrlFiles(item);
                }
            }
        }
예제 #2
0
 private bool ReadFromCache(String filename, Byte[] buffer, ref int readBytes,
     long offset, int offset_buf, Metadata meta)
 {
     // get block number
     int block = (int)(offset / precache_bytes);
     // get cache buffer
     byte[] cbuf = fileCaches[meta.path][block.ToString()];
     if (cbuf != null)
     {
         // block is cached, no need to make expensive network calls
         Debug.WriteLine("CacheHit! ReadFile {0} {1}", filename, offset);
         // calculate how many bytes can be read from cache
         int toCopy = cbuf.Length - (int)(offset % precache_bytes);
         if ((buffer.Length-offset_buf) < toCopy)
         {
             toCopy = (buffer.Length - offset_buf);
         }
         // read bytes from cache
         Buffer.BlockCopy(cbuf, (int)(offset % precache_bytes), buffer, offset_buf, toCopy);
         readBytes = toCopy;
         if (offset_buf + toCopy < buffer.Length && cbuf.Length == precache_bytes)
         {
             // still have data to read
             return false;
         }
         else
         {
             // done!
             return true;
         }
     }
     readBytes = 0;
     return false;
 }