protected HResult HydrateFile()

in simpleProviderManaged/SimpleProvider.cs [251:285]


        protected HResult HydrateFile(string relativePath, uint bufferSize, Func<byte[], uint, bool> tryWriteBytes)
        {
            string layerPath = this.GetFullPathInLayer(relativePath);
            if (!File.Exists(layerPath))
            {
                return HResult.FileNotFound;
            }

            // Open the file in the layer for read.
            using (FileStream fs = new FileStream(layerPath, FileMode.Open, FileAccess.Read))
            {
                long remainingDataLength = fs.Length;
                byte[] buffer = new byte[bufferSize];

                while (remainingDataLength > 0)
                {
                    // Read from the file into the read buffer.
                    int bytesToCopy = (int)Math.Min(remainingDataLength, buffer.Length);
                    if (fs.Read(buffer, 0, bytesToCopy) != bytesToCopy)
                    {
                        return HResult.InternalError;
                    }

                    // Write the bytes we just read into the scratch.
                    if (!tryWriteBytes(buffer, (uint)bytesToCopy))
                    {
                        return HResult.InternalError;
                    }

                    remainingDataLength -= bytesToCopy;
                }
            }

            return HResult.Ok;
        }