Esempio n. 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() && (uri.Scheme.Equals(Uri.UriSchemeHttp,
                                                         StrUtil.CaseIgnoreCmp) || uri.Scheme.Equals(Uri.UriSchemeHttps,
                                                                                                     StrUtil.CaseIgnoreCmp)))
            {
                s = CreateWebClient(ioc).OpenWrite(uri, WebRequestMethods.Http.Put);
            }
            else
            {
                s = CreateWebClient(ioc).OpenWrite(uri);
            }

            return(IocStream.WrapIfRequired(s));
        }
Esempio n. 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))));
        }