Ejemplo n.º 1
0
        public IEnumerator Read()
        {
            // Given an existing file in a relative path.
            Assert.IsTrue(defaultFileSystem.Exists(RelativeFilePath));

            // When reading the file from the relative path.
            byte[] fileData = defaultFileSystem.Read(RelativeFilePath);
            string message  = Encoding.Default.GetString(fileData);

            // Then assert that the file content was retrieved.
            Assert.That(fileData != null && fileData.Length > 0);
            Assert.IsFalse(string.IsNullOrEmpty(message));
            yield break;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Loads a file stored at <paramref name="filePath"/>.
        /// </summary>
        /// <remarks><paramref name="filePath"/> must be relative to the StreamingAssets or the persistent data folder.</remarks>
        /// <returns>The contents of the file into a byte array.</returns>
        /// <exception cref="ArgumentException">Exception thrown if <paramref name="filePath"/> is invalid.</exception>
        /// <exception cref="FileNotFoundException">Exception thrown if the file does not exist.</exception>
        public static byte[] Read(string filePath)
        {
            if (string.IsNullOrEmpty(filePath))
            {
                throw new ArgumentException("Invalid 'filePath'");
            }

            if (Path.IsPathRooted(filePath))
            {
                throw new ArgumentException($"Method only accepts relative paths.\n'filePath': {filePath}");
            }

            return(platformFileSystem.Read(filePath));
        }