コード例 #1
0
        public override void OnGetDataNow(ContentPackage package)
        {
            // Main thread only:
            Callback.MainThread(delegate(){
                // Getting a files text content from resources.
                byte[] data = null;

                string path = GetPath(package.location);

                TextAsset asset = Resources.Load(path) as TextAsset;

                if (asset == null)
                {
                    // Not found
                    package.Failed(404);
                }
                else
                {
                    // Ok
                    data = asset.bytes;
                    package.ReceivedHeaders(data.Length);
                    package.ReceivedData(data, 0, data.Length);
                }
            });
        }
コード例 #2
0
        /// <summary>Get the raw file data.</summary>
        public override void OnGetDataNow(ContentPackage package)
        {
            // Path without the protocol:
            string rawPath = package.location.Path;

            // If it contains a : and starts with / then chop it off:
            if (rawPath != null && rawPath.IndexOf(':') != -1 && rawPath[0] == '/')
            {
                rawPath = rawPath.Substring(1);
            }

            if (File.Exists(rawPath))
            {
                // Partial?
                int partialStart;
                int partialEnd;

                byte[] data;

                if (package.GetRange(out partialStart, out partialEnd))
                {
                    // Partial request.
                    FileStream fs = new FileStream(rawPath, FileMode.Open, FileAccess.Read);

                    // Seek there:
                    fs.Seek(partialStart, SeekOrigin.Begin);

                    // Setup Content-Range:
                    package.SetPartialResponse(partialStart, partialEnd, (int)fs.Length);

                    int contentLength = (partialEnd + 1) - partialStart;

                    // Read that many bytes into our buffer:
                    data = new byte[contentLength];

                    // Read:
                    fs.Read(data, 0, data.Length);

                    // Got headers:
                    package.ReceivedHeaders(contentLength);

                    // Ok!
                    fs.Close();
                }
                else
                {
                    // Get the bytes:
                    data = File.ReadAllBytes(rawPath);

                    // Got headers:
                    package.ReceivedHeaders(data.Length);
                }

                // Got data:
                package.ReceivedData(data, 0, data.Length);
            }
            else
            {
                // Let the package know:
                package.Failed(404);
            }
        }
コード例 #3
0
 /// <summary>Get the raw file data.</summary>
 public override void OnGetDataNow(ContentPackage package)
 {
     // Unsupported!
     package.Failed(501);
 }