Пример #1
0
        private static void TempFileConvenienceMethods(ITempStorage tempStorage)
        {
            using ITempFile tempFile = tempStorage.NewTempFile();

            // text content
            tempFile.WriteAllText("some file content", Encoding.UTF8);
            string contents = tempFile.ReadAllText(Encoding.UTF8);

            // binary content
            byte[] bytes = tempFile.ReadAllBytes();
            tempFile.WriteAllBytes(bytes);

            // streams
            using (FileStream stream = tempFile.OpenRead())
            {
                stream.Read(bytes);
            }

            using (FileStream stream = tempFile.OpenWrite())
            {
                stream.Write(bytes);
            }
        }
Пример #2
0
 private static void CreateTemporaryFile(ITempStorage tempStorage)
 {
     using ITempFile tempFile = tempStorage.NewTempFile();
     tempFile.WriteAllBytes(new byte[] { 0x2a });
 }
Пример #3
0
 private static void CreateTemporaryFileWithExtension(ITempStorage tempStorage)
 {
     using ITempFile tempFile = tempStorage.NewTempFile("txt");
     tempFile.WriteAllText("some file content");
 }
Пример #4
0
 public IEnumerable <WeatherForecast> Get()
 {
     using var tempFile = tempStorage.NewTempFile("json");
     WriteSampleDataTo(tempFile);
     return(ReadSampleDataFrom(tempFile));
 }