Пример #1
0
        public static Stream OpenWrite(IOConnectionInfo ioc)
        {
            if (ioc == null)
            {
                Debug.Assert(false); return(null);
            }

            RaiseIOAccessPreEvent(ioc, IOAccessType.Write);

            if (ioc.IsLocalFile())
            {
                return(OpenWriteLocal(ioc));
            }

            Uri    uri = new Uri(ioc.Path);
            Stream s;

            // Mono does not set HttpWebRequest.Method to POST for writes,
            // so one needs to set the method to PUT explicitly
            if (NativeLib.IsUnix() && IsHttpWebRequest(uri))
            {
                s = CreateWebClient(ioc).OpenWrite(uri, WebRequestMethods.Http.Put);
            }
            else
            {
                s = CreateWebClient(ioc).OpenWrite(uri);
            }

            return(IocStream.WrapIfRequired(s));
        }
Пример #2
0
        public static Stream OpenRead(IOConnectionInfo ioc)
        {
            RaiseIOAccessPreEvent(ioc, IOAccessType.Read);

            if (StrUtil.IsDataUri(ioc.Path))
            {
                byte[] pbData = StrUtil.DataUriToData(ioc.Path);
                if (pbData != null)
                {
                    return(new MemoryStream(pbData, false));
                }
            }

            if (ioc.IsLocalFile())
            {
                return(OpenReadLocal(ioc));
            }

            return(IocStream.WrapIfRequired(CreateWebClient(ioc).OpenRead(
                                                new Uri(ioc.Path))));
        }